From f74ff067318cc3ce3439fefa08f262fd67db2d24 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Wed, 30 Jan 2019 10:28:22 -0500 Subject: [PATCH] More tests for silent status bar setting Test: this Change-Id: I2f1890a4843438684c089b837cf74bd520b352e6 Fixes: 123419917 --- .../SilentStatusBarPreferenceController.java | 9 ++++++++- .../SilentStatusBarPreferenceControllerTest.java | 10 ++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java index 4721f5c9b27..5bf943ac37a 100644 --- a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java +++ b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java @@ -24,17 +24,24 @@ import android.provider.Settings; import com.android.settings.core.TogglePreferenceController; +import com.google.common.annotations.VisibleForTesting; + public class SilentStatusBarPreferenceController extends TogglePreferenceController { private static final String KEY = "hide_silent_icons"; private static final int MY_USER_ID = UserHandle.myUserId(); - private final NotificationBackend mBackend; + private NotificationBackend mBackend; public SilentStatusBarPreferenceController(Context context) { super(context, KEY); mBackend = new NotificationBackend(); } + @VisibleForTesting + void setBackend(NotificationBackend backend) { + mBackend = backend; + } + @Override public boolean isChecked() { return mBackend.shouldHideSilentStatusBarIcons(mContext); diff --git a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java index 8a43a1ea2c4..9dd8ff9f5c6 100644 --- a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java @@ -48,7 +48,6 @@ public class SilentStatusBarPreferenceControllerTest { @Mock private PreferenceScreen mScreen; - private FakeFeatureFactory mFeatureFactory; private Context mContext; private SilentStatusBarPreferenceController mController; private Preference mPreference; @@ -57,8 +56,8 @@ public class SilentStatusBarPreferenceControllerTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; - mFeatureFactory = FakeFeatureFactory.setupForTest(); mController = new SilentStatusBarPreferenceController(mContext); + mController.setBackend(mBackend); mPreference = new Preference(mContext); mPreference.setKey(mController.getPreferenceKey()); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); @@ -83,7 +82,7 @@ public class SilentStatusBarPreferenceControllerTest { when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(false); assertThat(mController.isChecked()).isFalse(); } -/** + @Test public void isChecked_settingIsOn_true() { when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(true); @@ -93,18 +92,13 @@ public class SilentStatusBarPreferenceControllerTest { @Test public void onPreferenceChange_on() { mController.onPreferenceChange(mPreference, true); - - assertThat(mController.isChecked()).isTrue(); verify(mBackend).setHideSilentStatusIcons(true); } @Test public void onPreferenceChange_off() { mController.onPreferenceChange(mPreference, false); - - assertThat(mController.isChecked()).isFalse(); verify(mBackend).setHideSilentStatusIcons(false); } - **/ }