Merge "Add null check in displayPreference"

This commit is contained in:
TreeHugger Robot
2018-06-05 18:14:17 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 1 deletions

View File

@@ -68,8 +68,11 @@ public class ZenModeStarredContactsPreferenceController extends
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(KEY);
if (mPreference != null) {
mPreference.setOnPreferenceClickListener(this);
}
}
@Override
public String getPreferenceKey() {

View File

@@ -190,4 +190,13 @@ public class ZenModeStarredContactsPreferenceControllerTest {
assertThat(contacts.get(i)).isNotNull();
}
}
@Test
public void nullPreference_displayPreference() {
when(mPreferenceScreen.findPreference(mMessagesController.getPreferenceKey()))
.thenReturn(null);
// should not throw a null pointer
mMessagesController.displayPreference(mPreferenceScreen);
}
}