From 52ee33df19b42bae9ddf6e3ed360068e694b7d36 Mon Sep 17 00:00:00 2001 From: Chloris Kuo Date: Wed, 2 Jun 2021 19:46:43 -0700 Subject: [PATCH] Fix flaky NotificationAssistantPreferenceControllerTest Fix test failures due to we set the Settings.Secure.NAS_SETTINGS_UPDATED in NMS instead of in NotificationAssistantPreferenceController. Move some tests to NotificationManagerServiceTest (in another CL) Bug: 187999823 Test: make RunSettingsRoboTests Change-Id: Ibfbaa2c8c15e49a14a7faeda50ec044f62b2fe72 --- ...tionAssistantPreferenceControllerTest.java | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java index 9b45a9808eb..fe36615c569 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java @@ -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()); } }