Merge "Use getSummary in ZenStarredContactPrefController"
This commit is contained in:
committed by
Android (Google) Code Review
commit
dbb465fbce
@@ -46,10 +46,8 @@ public class ZenModeStarredContactsPreferenceController extends
|
|||||||
private final int mPriorityCategory;
|
private final int mPriorityCategory;
|
||||||
private final PackageManager mPackageManager;
|
private final PackageManager mPackageManager;
|
||||||
|
|
||||||
@VisibleForTesting
|
private Intent mStarredContactsIntent;
|
||||||
Intent mStarredContactsIntent;
|
private Intent mFallbackIntent;
|
||||||
@VisibleForTesting
|
|
||||||
Intent mFallbackIntent;
|
|
||||||
|
|
||||||
public ZenModeStarredContactsPreferenceController(Context context, Lifecycle lifecycle, int
|
public ZenModeStarredContactsPreferenceController(Context context, Lifecycle lifecycle, int
|
||||||
priorityCategory, String key) {
|
priorityCategory, String key) {
|
||||||
@@ -97,9 +95,7 @@ public class ZenModeStarredContactsPreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public CharSequence getSummary() {
|
||||||
super.updateState(preference);
|
|
||||||
|
|
||||||
List<String> starredContacts = getStarredContacts();
|
List<String> starredContacts = getStarredContacts();
|
||||||
int numStarredContacts = starredContacts.size();
|
int numStarredContacts = starredContacts.size();
|
||||||
|
|
||||||
@@ -122,7 +118,7 @@ public class ZenModeStarredContactsPreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
// values in displayContacts must not be null
|
// values in displayContacts must not be null
|
||||||
mPreference.setSummary(ListFormatter.getInstance().format(displayContacts));
|
return ListFormatter.getInstance().format(displayContacts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -156,22 +156,7 @@ public class ZenModeStarredContactsPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateSummary_nullCursorValues() {
|
public void updateSummary_nullCursorValues() {
|
||||||
Cursor testCursorWithNullValues = mock(Cursor.class);
|
Cursor testCursorWithNullValues = createMockCursor(3);
|
||||||
when(testCursorWithNullValues.moveToFirst()).thenReturn(true);
|
|
||||||
|
|
||||||
doAnswer(new Answer<Boolean>() {
|
|
||||||
int count = 0;
|
|
||||||
@Override
|
|
||||||
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
|
||||||
if (count < 3) {
|
|
||||||
count++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}).when(testCursorWithNullValues).moveToNext();
|
|
||||||
|
|
||||||
when(testCursorWithNullValues.getString(0)).thenReturn(null);
|
when(testCursorWithNullValues.getString(0)).thenReturn(null);
|
||||||
|
|
||||||
// expected - no null values
|
// expected - no null values
|
||||||
@@ -189,4 +174,24 @@ public class ZenModeStarredContactsPreferenceControllerTest {
|
|||||||
// should not throw a null pointer
|
// should not throw a null pointer
|
||||||
mMessagesController.displayPreference(mPreferenceScreen);
|
mMessagesController.displayPreference(mPreferenceScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Cursor createMockCursor(int size) {
|
||||||
|
Cursor mockCursor = mock(Cursor.class);
|
||||||
|
when(mockCursor.moveToFirst()).thenReturn(true);
|
||||||
|
|
||||||
|
doAnswer(new Answer<Boolean>() {
|
||||||
|
int count = 0;
|
||||||
|
@Override
|
||||||
|
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
if (count < size) {
|
||||||
|
count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}).when(mockCursor).moveToNext();
|
||||||
|
|
||||||
|
return mockCursor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user