Merge "Fix VisibilityPreferenceControllerTest."

This commit is contained in:
TreeHugger Robot
2017-12-11 18:45:33 +00:00
committed by Android (Google) Code Review

View File

@@ -205,9 +205,10 @@ public class VisibilityPreferenceControllerTest {
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
mController.updateState(pref); mController.updateState(pref);
ArgumentCaptor<String[]> argumentCaptor = ArgumentCaptor.forClass(String[].class); ArgumentCaptor<CharSequence[]> argumentCaptor =
ArgumentCaptor.forClass(CharSequence[].class);
verify(pref, times(1)).setEntryValues(argumentCaptor.capture()); verify(pref, times(1)).setEntryValues(argumentCaptor.capture());
assertFalse(Arrays.asList(argumentCaptor.getValue()) assertFalse(toStringList(argumentCaptor.getValue())
.contains(VISIBILITY_NO_OVERRIDE)); .contains(VISIBILITY_NO_OVERRIDE));
} }
@@ -223,9 +224,10 @@ public class VisibilityPreferenceControllerTest {
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
mController.updateState(pref); mController.updateState(pref);
ArgumentCaptor<String[]> argumentCaptor = ArgumentCaptor.forClass(String[].class); ArgumentCaptor<CharSequence[]> argumentCaptor =
ArgumentCaptor.forClass(CharSequence[].class);
verify(pref, times(1)).setEntryValues(argumentCaptor.capture()); verify(pref, times(1)).setEntryValues(argumentCaptor.capture());
assertFalse(Arrays.asList(argumentCaptor.getValue()) assertFalse(toStringList(argumentCaptor.getValue())
.contains(VISIBILITY_NO_OVERRIDE)); .contains(VISIBILITY_NO_OVERRIDE));
} }
@@ -238,15 +240,24 @@ public class VisibilityPreferenceControllerTest {
RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class); RestrictedDropDownPreference pref = mock(RestrictedDropDownPreference.class);
mController.updateState(pref); mController.updateState(pref);
ArgumentCaptor<String[]> argumentCaptor = ArgumentCaptor.forClass(String[].class); ArgumentCaptor<CharSequence[]> argumentCaptor =
ArgumentCaptor.forClass(CharSequence[].class);
verify(pref, times(1)).setEntryValues(argumentCaptor.capture()); verify(pref, times(1)).setEntryValues(argumentCaptor.capture());
List<String> values = Arrays.asList(argumentCaptor.getValue()); List<String> values = toStringList(argumentCaptor.getValue());
assertEquals(3, values.size()); assertEquals(3, values.size());
assertTrue(values.contains(String.valueOf(VISIBILITY_NO_OVERRIDE))); assertTrue(values.contains(String.valueOf(VISIBILITY_NO_OVERRIDE)));
assertTrue(values.contains(String.valueOf(Notification.VISIBILITY_PRIVATE))); assertTrue(values.contains(String.valueOf(Notification.VISIBILITY_PRIVATE)));
assertTrue(values.contains(String.valueOf(Notification.VISIBILITY_SECRET))); assertTrue(values.contains(String.valueOf(Notification.VISIBILITY_SECRET)));
} }
private static List<String> toStringList(CharSequence[] charSequences) {
List<String> result = new ArrayList<>();
for (CharSequence charSequence : charSequences) {
result.add(charSequence.toString());
}
return result;
}
@Test @Test
public void testUpdateState_noChannelOverride() throws Exception { public void testUpdateState_noChannelOverride() throws Exception {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.putInt(mContext.getContentResolver(),