diff --git a/res/values/bools.xml b/res/values/bools.xml
index 687d5bd1ddc..c1f5ad0c8b6 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -60,6 +60,27 @@
true
+
+ true
+
+
+ true
+
+
+ true
+
+
+ true
+
+
+ true
+
+
+ true
+
+
+ true
+
true
diff --git a/src/com/android/settings/notification/AlarmVolumePreferenceController.java b/src/com/android/settings/notification/AlarmVolumePreferenceController.java
index cd1f6e39cd6..c9b283b5741 100644
--- a/src/com/android/settings/notification/AlarmVolumePreferenceController.java
+++ b/src/com/android/settings/notification/AlarmVolumePreferenceController.java
@@ -21,6 +21,7 @@ import android.media.AudioManager;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class AlarmVolumePreferenceController extends
@@ -43,7 +44,8 @@ public class AlarmVolumePreferenceController extends
@Override
public boolean isAvailable() {
- return !mHelper.isSingleVolume();
+ return mContext.getResources().getBoolean(R.bool.config_show_alarm_volume)
+ && !mHelper.isSingleVolume();
}
@Override
diff --git a/src/com/android/settings/notification/ChargingSoundPreferenceController.java b/src/com/android/settings/notification/ChargingSoundPreferenceController.java
index 55cba9677f0..e280177ce6d 100644
--- a/src/com/android/settings/notification/ChargingSoundPreferenceController.java
+++ b/src/com/android/settings/notification/ChargingSoundPreferenceController.java
@@ -21,6 +21,7 @@ import static com.android.settings.notification.SettingPref.TYPE_GLOBAL;
import android.content.Context;
import android.provider.Settings.Global;
+import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -33,7 +34,10 @@ public class ChargingSoundPreferenceController extends SettingPrefController {
super(context, parent, lifecycle);
mPreference = new SettingPref(
TYPE_GLOBAL, KEY_CHARGING_SOUNDS, Global.CHARGING_SOUNDS_ENABLED, DEFAULT_ON);
-
}
+ @Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(R.bool.config_show_charging_sounds);
+ }
}
diff --git a/src/com/android/settings/notification/MediaVolumePreferenceController.java b/src/com/android/settings/notification/MediaVolumePreferenceController.java
index 4f167f8750d..381135e0956 100644
--- a/src/com/android/settings/notification/MediaVolumePreferenceController.java
+++ b/src/com/android/settings/notification/MediaVolumePreferenceController.java
@@ -19,6 +19,7 @@ package com.android.settings.notification;
import android.content.Context;
import android.media.AudioManager;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class MediaVolumePreferenceController extends
@@ -32,7 +33,7 @@ public class MediaVolumePreferenceController extends
@Override
public boolean isAvailable() {
- return true;
+ return mContext.getResources().getBoolean(R.bool.config_show_media_volume);
}
@Override
diff --git a/src/com/android/settings/notification/NotificationRingtonePreferenceController.java b/src/com/android/settings/notification/NotificationRingtonePreferenceController.java
index 72e8d8f54d6..00f478f2d28 100644
--- a/src/com/android/settings/notification/NotificationRingtonePreferenceController.java
+++ b/src/com/android/settings/notification/NotificationRingtonePreferenceController.java
@@ -19,6 +19,8 @@ package com.android.settings.notification;
import android.content.Context;
import android.media.RingtoneManager;
+import com.android.settings.R;
+
public class NotificationRingtonePreferenceController extends RingtonePreferenceControllerBase {
private static final String KEY_NOTIFICATION_RINGTONE = "notification_ringtone";
@@ -27,6 +29,11 @@ public class NotificationRingtonePreferenceController extends RingtonePreference
super(context);
}
+ @Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(R.bool.config_show_notification_ringtone);
+ }
+
@Override
public String getPreferenceKey() {
return KEY_NOTIFICATION_RINGTONE;
diff --git a/src/com/android/settings/notification/NotificationVolumePreferenceController.java b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
index 5f888f8af65..4024f9fcf21 100644
--- a/src/com/android/settings/notification/NotificationVolumePreferenceController.java
+++ b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.media.AudioManager;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -45,7 +46,8 @@ public class NotificationVolumePreferenceController extends
@Override
public boolean isAvailable() {
- return !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume();
+ return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
+ && !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume();
}
@Override
diff --git a/src/com/android/settings/notification/ScreenLockSoundPreferenceController.java b/src/com/android/settings/notification/ScreenLockSoundPreferenceController.java
index b08b8f84090..11aaa92dd01 100644
--- a/src/com/android/settings/notification/ScreenLockSoundPreferenceController.java
+++ b/src/com/android/settings/notification/ScreenLockSoundPreferenceController.java
@@ -21,6 +21,7 @@ import static com.android.settings.notification.SettingPref.TYPE_SYSTEM;
import android.content.Context;
import android.provider.Settings.System;
+import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -35,4 +36,8 @@ public class ScreenLockSoundPreferenceController extends SettingPrefController {
TYPE_SYSTEM, KEY_SCREEN_LOCKING_SOUNDS, System.LOCKSCREEN_SOUNDS_ENABLED, DEFAULT_ON);
}
+ @Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(R.bool.config_show_screen_locking_sounds);
+ }
}
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index 6e998f6fe32..4a27b11a49f 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -33,6 +33,7 @@ import com.android.settings.R;
import com.android.settings.RingtonePreference;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -201,15 +202,45 @@ public class SoundSettings extends DashboardFragment {
controllers.add(new WorkSoundPreferenceController(context, fragment, lifecycle));
// === Other Sound Settings ===
- controllers.add(new DialPadTonePreferenceController(context, fragment, lifecycle));
- controllers.add(new ScreenLockSoundPreferenceController(context, fragment, lifecycle));
- controllers.add(new ChargingSoundPreferenceController(context, fragment, lifecycle));
- controllers.add(new DockingSoundPreferenceController(context, fragment, lifecycle));
- controllers.add(new TouchSoundPreferenceController(context, fragment, lifecycle));
- controllers.add(new VibrateOnTouchPreferenceController(context, fragment, lifecycle));
- controllers.add(new DockAudioMediaPreferenceController(context, fragment, lifecycle));
- controllers.add(new BootSoundPreferenceController(context));
- controllers.add(new EmergencyTonePreferenceController(context, fragment, lifecycle));
+ final DialPadTonePreferenceController dialPadTonePreferenceController =
+ new DialPadTonePreferenceController(context, fragment, lifecycle);
+ final ScreenLockSoundPreferenceController screenLockSoundPreferenceController =
+ new ScreenLockSoundPreferenceController(context, fragment, lifecycle);
+ final ChargingSoundPreferenceController chargingSoundPreferenceController =
+ new ChargingSoundPreferenceController(context, fragment, lifecycle);
+ final DockingSoundPreferenceController dockingSoundPreferenceController =
+ new DockingSoundPreferenceController(context, fragment, lifecycle);
+ final TouchSoundPreferenceController touchSoundPreferenceController =
+ new TouchSoundPreferenceController(context, fragment, lifecycle);
+ final VibrateOnTouchPreferenceController vibrateOnTouchPreferenceController =
+ new VibrateOnTouchPreferenceController(context, fragment, lifecycle);
+ final DockAudioMediaPreferenceController dockAudioMediaPreferenceController =
+ new DockAudioMediaPreferenceController(context, fragment, lifecycle);
+ final BootSoundPreferenceController bootSoundPreferenceController =
+ new BootSoundPreferenceController(context);
+ final EmergencyTonePreferenceController emergencyTonePreferenceController =
+ new EmergencyTonePreferenceController(context, fragment, lifecycle);
+
+ controllers.add(dialPadTonePreferenceController);
+ controllers.add(screenLockSoundPreferenceController);
+ controllers.add(chargingSoundPreferenceController);
+ controllers.add(dockingSoundPreferenceController);
+ controllers.add(touchSoundPreferenceController);
+ controllers.add(vibrateOnTouchPreferenceController);
+ controllers.add(dockAudioMediaPreferenceController);
+ controllers.add(bootSoundPreferenceController);
+ controllers.add(emergencyTonePreferenceController);
+ controllers.add(new PreferenceCategoryController(context,
+ "other_sounds_and_vibrations_category",
+ Arrays.asList(dialPadTonePreferenceController,
+ screenLockSoundPreferenceController,
+ chargingSoundPreferenceController,
+ dockingSoundPreferenceController,
+ touchSoundPreferenceController,
+ vibrateOnTouchPreferenceController,
+ dockAudioMediaPreferenceController,
+ bootSoundPreferenceController,
+ emergencyTonePreferenceController)));
return controllers;
}
diff --git a/src/com/android/settings/notification/TouchSoundPreferenceController.java b/src/com/android/settings/notification/TouchSoundPreferenceController.java
index 4e25507aef1..20c9cee0d05 100644
--- a/src/com/android/settings/notification/TouchSoundPreferenceController.java
+++ b/src/com/android/settings/notification/TouchSoundPreferenceController.java
@@ -23,6 +23,7 @@ import android.content.Context;
import android.media.AudioManager;
import android.os.AsyncTask;
import android.provider.Settings.System;
+import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -53,4 +54,9 @@ public class TouchSoundPreferenceController extends SettingPrefController {
}
};
}
+
+ @Override
+ public boolean isAvailable() {
+ return mContext.getResources().getBoolean(R.bool.config_show_touch_sounds);
+ }
}
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index e10fee1e080..90a22372ed4 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -22,6 +22,13 @@
false
false
false
+ false
+ false
+ false
+ false
+ false
+ false
+ false
false
false
false
diff --git a/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
index 7b0b0333041..b2fbb004f7c 100644
--- a/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/AlarmVolumePreferenceControllerTest.java
@@ -27,28 +27,37 @@ 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 static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class AlarmVolumePreferenceControllerTest {
- @Mock
- private Context mContext;
@Mock
private AudioHelper mHelper;
+ private Context mContext;
private AlarmVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
mController = new AlarmVolumePreferenceController(mContext, null, null, mHelper);
}
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
@Test
public void isAvailable_singleVolume_shouldReturnFalse() {
when(mHelper.isSingleVolume()).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
index 2b2d024ee80..c24f02e2ed4 100644
--- a/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java
@@ -31,11 +31,13 @@ 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -50,15 +52,15 @@ public class ChargingSoundPreferenceControllerTest {
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
- @Mock
- private Context mContext;
+ private Context mContext;
private ChargingSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
@@ -68,10 +70,16 @@ public class ChargingSoundPreferenceControllerTest {
}
@Test
- public void isAvailable_isAlwaysTrue() {
+ public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
@Test
public void displayPreference_chargingSoundEnabled_shouldCheckedPreference() {
Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1);
diff --git a/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
index ca7fc444565..688575abdd3 100644
--- a/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/MediaVolumePreferenceControllerTest.java
@@ -27,30 +27,38 @@ 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 static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.spy;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class MediaVolumePreferenceControllerTest {
- @Mock
private Context mContext;
-
private MediaVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
mController = new MediaVolumePreferenceController(mContext, null, null);
}
@Test
- public void isAlwaysAvailable() {
+ public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
@Test
public void getAudioStream_shouldReturnMusic() {
assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_MUSIC);
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
index 940a948ea5c..f712ec8e49f 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationRingtonePreferenceControllerTest.java
@@ -27,24 +27,38 @@ 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 static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.spy;
+
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NotificationRingtonePreferenceControllerTest {
- @Mock
private Context mContext;
private NotificationRingtonePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
mController = new NotificationRingtonePreferenceController(mContext);
}
+ @Test
+ public void isAvailable_byDefault_isTrue() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
@Test
public void getRingtoneType_shouldReturnNotification() {
assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_NOTIFICATION);
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
index f919e7bc313..131fb188363 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationVolumePreferenceControllerTest.java
@@ -29,17 +29,18 @@ 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 static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class NotificationVolumePreferenceControllerTest {
- @Mock
- private Context mContext;
@Mock
private AudioHelper mHelper;
@Mock
@@ -49,17 +50,25 @@ public class NotificationVolumePreferenceControllerTest {
@Mock
private Vibrator mVibrator;
+ private Context mContext;
private NotificationVolumePreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
mController = new NotificationVolumePreferenceController(mContext, null, null, mHelper);
}
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_shouldReturnFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
@Test
public void isAvailable_singleVolume_shouldReturnFalse() {
when(mHelper.isSingleVolume()).thenReturn(true);
diff --git a/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
index f94f8bfe4b9..e6a871840dc 100644
--- a/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ScreenLockSoundPreferenceControllerTest.java
@@ -31,11 +31,13 @@ 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -50,15 +52,15 @@ public class ScreenLockSoundPreferenceControllerTest {
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
- @Mock
- private Context mContext;
+ private Context mContext;
private ScreenLockSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
@@ -68,10 +70,16 @@ public class ScreenLockSoundPreferenceControllerTest {
}
@Test
- public void isAvailable_isAlwaysTrue() {
+ public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
@Test
public void displayPreference_lockScreenSoundEnabled_shouldCheckedPreference() {
System.putInt(mContentResolver, System.LOCKSCREEN_SOUNDS_ENABLED, 1);
diff --git a/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
index eaf9bb5e963..d9145fff6b1 100644
--- a/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/TouchSoundPreferenceControllerTest.java
@@ -32,11 +32,13 @@ 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 com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -54,15 +56,15 @@ public class TouchSoundPreferenceControllerTest {
private ContentResolver mContentResolver;
@Mock
private SoundSettings mSetting;
- @Mock
- private Context mContext;
+ private Context mContext;
private TouchSoundPreferenceController mController;
private SwitchPreference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
when(mActivity.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
when(mSetting.getActivity()).thenReturn(mActivity);
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
@@ -73,10 +75,16 @@ public class TouchSoundPreferenceControllerTest {
}
@Test
- public void isAvailable_isAlwaysTrue() {
+ public void isAvailable_byDefault_isTrue() {
assertThat(mController.isAvailable()).isTrue();
}
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void isAvailable_whenNotVisible_isFalse() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
@Test
public void displayPreference_soundEffectEnabled_shouldCheckedPreference() {
System.putInt(mContentResolver, System.SOUND_EFFECTS_ENABLED, 1);