Loading src/com/android/settings/dashboard/SupportItemAdapter.java +7 −2 Original line number Diff line number Diff line Loading @@ -170,8 +170,13 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd public void setAccounts(Account accounts[]) { if (!Arrays.equals(mAccounts, accounts)) { int index = ArrayUtils.indexOf(accounts, mAccounts[mSelectedAccountIndex]); if (mAccounts.length == 0) { mSelectedAccountIndex = 0; } else { final int index = ArrayUtils.indexOf(accounts, mAccounts[mSelectedAccountIndex]); mSelectedAccountIndex = index != -1 ? index : 0; } mAccounts = accounts; mSupportFeatureProvider.refreshOperationRules(); refreshEscalationCards(); Loading tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ public class SupportItemAdapterTest { private final Account USER_2 = new Account("user2", ACCOUNT_TYPE); private final Account TWO_ACCOUNTS[] = {USER_1, USER_2}; private final Account ONE_ACCOUNT[] = {USER_1}; private final Account ZERO_ACCOUNT[] = {}; private ShadowActivity mShadowActivity; private Activity mActivity; Loading Loading @@ -98,6 +99,18 @@ public class SupportItemAdapterTest { verify(mSupportFeatureProvider).getAccountLoginIntent(); } @Test public void testSetAccount_AccountEmpty_NotCrash() { when(mSupportFeatureProvider.getSupportEligibleAccounts(mActivity)).thenReturn(ZERO_ACCOUNT); mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider, mMetricsFeatureProvider, null); // Should not crash in this method mSupportItemAdapter.setAccounts(ONE_ACCOUNT); verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity); } /** * Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is * invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref Loading Loading
src/com/android/settings/dashboard/SupportItemAdapter.java +7 −2 Original line number Diff line number Diff line Loading @@ -170,8 +170,13 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd public void setAccounts(Account accounts[]) { if (!Arrays.equals(mAccounts, accounts)) { int index = ArrayUtils.indexOf(accounts, mAccounts[mSelectedAccountIndex]); if (mAccounts.length == 0) { mSelectedAccountIndex = 0; } else { final int index = ArrayUtils.indexOf(accounts, mAccounts[mSelectedAccountIndex]); mSelectedAccountIndex = index != -1 ? index : 0; } mAccounts = accounts; mSupportFeatureProvider.refreshOperationRules(); refreshEscalationCards(); Loading
tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ public class SupportItemAdapterTest { private final Account USER_2 = new Account("user2", ACCOUNT_TYPE); private final Account TWO_ACCOUNTS[] = {USER_1, USER_2}; private final Account ONE_ACCOUNT[] = {USER_1}; private final Account ZERO_ACCOUNT[] = {}; private ShadowActivity mShadowActivity; private Activity mActivity; Loading Loading @@ -98,6 +99,18 @@ public class SupportItemAdapterTest { verify(mSupportFeatureProvider).getAccountLoginIntent(); } @Test public void testSetAccount_AccountEmpty_NotCrash() { when(mSupportFeatureProvider.getSupportEligibleAccounts(mActivity)).thenReturn(ZERO_ACCOUNT); mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider, mMetricsFeatureProvider, null); // Should not crash in this method mSupportItemAdapter.setAccounts(ONE_ACCOUNT); verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity); } /** * Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is * invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref Loading