diff --git a/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java b/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java index a5137f1f5ce..622f994271a 100644 --- a/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java +++ b/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java @@ -46,10 +46,8 @@ public class ZenModeStarredContactsPreferenceController extends private final int mPriorityCategory; private final PackageManager mPackageManager; - @VisibleForTesting - Intent mStarredContactsIntent; - @VisibleForTesting - Intent mFallbackIntent; + private Intent mStarredContactsIntent; + private Intent mFallbackIntent; public ZenModeStarredContactsPreferenceController(Context context, Lifecycle lifecycle, int priorityCategory, String key) { @@ -97,9 +95,7 @@ public class ZenModeStarredContactsPreferenceController extends } @Override - public void updateState(Preference preference) { - super.updateState(preference); - + public CharSequence getSummary() { List starredContacts = getStarredContacts(); int numStarredContacts = starredContacts.size(); @@ -122,7 +118,7 @@ public class ZenModeStarredContactsPreferenceController extends } // values in displayContacts must not be null - mPreference.setSummary(ListFormatter.getInstance().format(displayContacts)); + return ListFormatter.getInstance().format(displayContacts); } @Override diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java index 5781c47f597..ca3654462b8 100644 --- a/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java @@ -156,22 +156,7 @@ public class ZenModeStarredContactsPreferenceControllerTest { @Test public void updateSummary_nullCursorValues() { - Cursor testCursorWithNullValues = mock(Cursor.class); - when(testCursorWithNullValues.moveToFirst()).thenReturn(true); - - doAnswer(new Answer() { - int count = 0; - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - if (count < 3) { - count++; - return true; - } - return false; - } - - }).when(testCursorWithNullValues).moveToNext(); - + Cursor testCursorWithNullValues = createMockCursor(3); when(testCursorWithNullValues.getString(0)).thenReturn(null); // expected - no null values @@ -189,4 +174,24 @@ public class ZenModeStarredContactsPreferenceControllerTest { // should not throw a null pointer mMessagesController.displayPreference(mPreferenceScreen); } + + private Cursor createMockCursor(int size) { + Cursor mockCursor = mock(Cursor.class); + when(mockCursor.moveToFirst()).thenReturn(true); + + doAnswer(new Answer() { + int count = 0; + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + if (count < size) { + count++; + return true; + } + return false; + } + + }).when(mockCursor).moveToNext(); + + return mockCursor; + } }