Fix account picker crash when there is no account before.

Bug: 33497222
Test: make RunSettingsRoboTests
Change-Id: I06adb4e0a4afcb359a4f7e8b15f13f67c28d5b46
This commit is contained in:
jackqdyulei
2016-12-11 12:32:35 -08:00
parent adab6060f1
commit 9134548ea4
2 changed files with 20 additions and 2 deletions

View File

@@ -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;
@@ -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