Merge "Use setVisible instead of removePreference everywhere."

This commit is contained in:
TreeHugger Robot
2017-11-10 00:02:58 +00:00
committed by Android (Google) Code Review
20 changed files with 239 additions and 271 deletions

View File

@@ -18,9 +18,7 @@ package com.android.settings.notification;
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -43,11 +41,12 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class BadgingNotificationPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -56,11 +55,15 @@ public class BadgingNotificationPreferenceControllerTest {
private PreferenceScreen mScreen;
private BadgingNotificationPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new BadgingNotificationPreferenceController(mContext);
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
@Test
@@ -70,7 +73,7 @@ public class BadgingNotificationPreferenceControllerTest {
.thenReturn(true);
mController.displayPreference(mScreen);
verify(mScreen, never()).removePreference(any(Preference.class));
assertThat(mPreference.isVisible()).isTrue();
}
@Test
@@ -78,14 +81,10 @@ public class BadgingNotificationPreferenceControllerTest {
when(mContext.getResources().
getBoolean(com.android.internal.R.bool.config_notificationBadging))
.thenReturn(false);
final Preference preference = mock(Preference.class);
when(mScreen.getPreferenceCount()).thenReturn(1);
when(mScreen.getPreference(0)).thenReturn(preference);
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
mController.displayPreference(mScreen);
verify(mScreen).removePreference(any(Preference.class));
assertThat(mPreference.isVisible()).isFalse();
}
@Test

View File

@@ -16,6 +16,12 @@
package com.android.settings.notification;
import static android.provider.Settings.System.NOTIFICATION_LIGHT_PULSE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.Preference;
@@ -31,18 +37,12 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static android.provider.Settings.System.NOTIFICATION_LIGHT_PULSE;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class PulseNotificationPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -51,11 +51,15 @@ public class PulseNotificationPreferenceControllerTest {
private PreferenceScreen mScreen;
private PulseNotificationPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new PulseNotificationPreferenceController(mContext);
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
@Test
@@ -65,7 +69,7 @@ public class PulseNotificationPreferenceControllerTest {
.thenReturn(true);
mController.displayPreference(mScreen);
verify(mScreen, never()).removePreference(any(Preference.class));
assertThat(mPreference.isVisible()).isTrue();
}
@Test
@@ -73,14 +77,10 @@ public class PulseNotificationPreferenceControllerTest {
when(mContext.getResources().
getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed))
.thenReturn(false);
final Preference preference = mock(Preference.class);
when(mScreen.getPreferenceCount()).thenReturn(1);
when(mScreen.getPreference(0)).thenReturn(preference);
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
mController.displayPreference(mScreen);
verify(mScreen).removePreference(any(Preference.class));
assertThat(mPreference.isVisible()).isFalse();
}
@Test

View File

@@ -16,6 +16,12 @@
package com.android.settings.notification;
import static android.provider.Settings.System.VIBRATE_WHEN_RINGING;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.Preference;
@@ -23,26 +29,20 @@ import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.TwoStatePreference;
import android.telephony.TelephonyManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import static android.provider.Settings.System.VIBRATE_WHEN_RINGING;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
public class VibrateWhenRingPreferenceControllerTest {
@Mock
@@ -53,36 +53,34 @@ public class VibrateWhenRingPreferenceControllerTest {
private TelephonyManager mTelephonyManager;
private VibrateWhenRingPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
mController = new VibrateWhenRingPreferenceController(mContext);
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
@Test
public void display_voiceCapable_shouldDisplay() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
when(mScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mock(Preference.class));
mController.displayPreference(mScreen);
verify(mScreen, never()).removePreference(any(Preference.class));
assertThat(mPreference.isVisible()).isTrue();
}
@Test
public void display_notVoiceCapable_shouldNotDisplay() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
final Preference preference = mock(Preference.class);
when(mScreen.getPreferenceCount()).thenReturn(1);
when(mScreen.getPreference(0)).thenReturn(preference);
when(preference.getKey()).thenReturn(mController.getPreferenceKey());
mController.displayPreference(mScreen);
verify(mScreen).removePreference(any(Preference.class));
assertThat(mPreference.isVisible()).isFalse();
}
@Test