Check instance before casting

Change-Id: I1917b2d8e045904145ea833abf35fa1d008fa224
Fixes: 116855783
Test: robotests
This commit is contained in:
Fan Zhang
2018-10-02 13:36:33 -07:00
parent 3600c03392
commit 53bdd9961c
2 changed files with 21 additions and 2 deletions

View File

@@ -94,4 +94,22 @@ public class SpecialAppAccessPreferenceControllerTest {
.isEqualTo(mContext.getResources().getQuantityString(
R.plurals.special_access_summary, 1, 1));
}
@Test
public void updateState_wrongExtraInfo_shouldNotIncludeInSummary() {
final ArrayList<ApplicationsState.AppEntry> apps = new ArrayList<>();
final ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
entry.hasLauncherEntry = true;
entry.info = new ApplicationInfo();
entry.extraInfo = new AppStateNotificationBridge.NotificationsSentState();
apps.add(entry);
when(mSession.getAllApps()).thenReturn(apps);
mController.displayPreference(mScreen);
mController.onExtraInfoUpdated();
assertThat(mPreference.getSummary())
.isEqualTo(mContext.getResources().getQuantityString(
R.plurals.special_access_summary, 0, 0));
}
}