Merge "Fix flaky NotificationAssistantPreferenceControllerTest" into sc-dev

This commit is contained in:
Chloris Kuo
2021-06-03 17:29:59 +00:00
committed by Android (Google) Code Review

View File

@@ -16,7 +16,6 @@
package com.android.settings.notification;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -24,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -117,18 +117,10 @@ public class NotificationAssistantPreferenceControllerTest {
//Test user enable for the first time
mPreferenceController.setNotificationAssistantGranted(mNASComponent);
assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 0));
assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 10));
verify(mBackend, times(1))
.setNASMigrationDoneAndResetDefault(eq(0), eq(true));
//Test user enable again, migration should not happen
mPreferenceController.setNotificationAssistantGranted(mNASComponent);
//Number of invocations should not increase
verify(mBackend, times(1))
.setNASMigrationDoneAndResetDefault(eq(0), eq(true));
verify(mBackend, never())
.setNASMigrationDoneAndResetDefault(eq(10), anyBoolean());
}
@Test
@@ -141,18 +133,10 @@ public class NotificationAssistantPreferenceControllerTest {
//Test user 0 enable for the first time
mPreferenceController.setNotificationAssistantGranted(mNASComponent);
assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 0));
assertEquals(0, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 20));
verify(mBackend, times(1))
.setNASMigrationDoneAndResetDefault(eq(0), eq(true));
//Test user enable again, migration should not happen
mPreferenceController.setNotificationAssistantGranted(mNASComponent);
//Number of invocations should not increase
verify(mBackend, times(1))
.setNASMigrationDoneAndResetDefault(eq(0), eq(true));
verify(mBackend, never())
.setNASMigrationDoneAndResetDefault(eq(20), anyBoolean());
}
@Test
@@ -165,18 +149,10 @@ public class NotificationAssistantPreferenceControllerTest {
//Test user disable for the first time
mPreferenceController.setChecked(false);
assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 0));
assertEquals(1, Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.NAS_SETTINGS_UPDATED, 0, 10));
verify(mBackend, times(1))
.setNASMigrationDoneAndResetDefault(eq(0), eq(false));
//Test user disable again, migration should not happen
mPreferenceController.setChecked(false);
//Number of invocations should not increase
verify(mBackend, times(1))
.setNASMigrationDoneAndResetDefault(eq(0), eq(false));
verify(mBackend, never())
.setNASMigrationDoneAndResetDefault(eq(10), anyBoolean());
}
}