Fix crash in Monkey test.

When battery page is launched, BatteryTipLoader will start running.
If we rotate the screen before loader is finished, it will store null
to Bundle and will crash when restoring from that Bundle.

In this cl, we add null pointer check for tip list to avoid the crash.

Also remove a TODO since it is obsolete.

Change-Id: Ic59bc20c633f3a7467f7b5e95da062160bcb4e93
Fixes: 77534165
Test: RunSettingsRoboTests
This commit is contained in:
Lei Yu
2018-04-03 17:25:18 -07:00
parent cf60ff7e08
commit fd62af5792
2 changed files with 16 additions and 1 deletions

View File

@@ -149,6 +149,19 @@ public class BatteryTipPreferenceControllerTest {
assertOnlyContainsSummaryTip(mPreferenceGroup);
}
@Test
public void testRestoreFromNull_shouldNotCrash() {
final Bundle bundle = new Bundle();
// Battery tip list is null at this time
mBatteryTipPreferenceController.saveInstanceState(bundle);
final BatteryTipPreferenceController controller = new BatteryTipPreferenceController(
mContext, KEY_PREF, mSettingsActivity, mFragment, mBatteryTipListener);
// Should not crash
controller.restoreInstanceState(bundle);
}
@Test
public void testHandlePreferenceTreeClick_noDialog_invokeCallback() {
when(mBatteryTip.getType()).thenReturn(SMART_BATTERY_MANAGER);