1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.notification; 18 19 import android.content.Context; 20 import android.media.AudioManager; 21 import android.os.Vibrator; 22 import android.telephony.TelephonyManager; 23 24 import com.android.settings.testutils.SettingsRobolectricTestRunner; 25 import com.android.settings.TestConfig; 26 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 import org.mockito.Mock; 31 import org.mockito.MockitoAnnotations; 32 import org.robolectric.annotation.Config; 33 34 import static com.google.common.truth.Truth.assertThat; 35 import static org.mockito.Mockito.when; 36 37 @RunWith(SettingsRobolectricTestRunner.class) 38 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 39 public class NotificationVolumePreferenceControllerTest { 40 41 @Mock 42 private Context mContext; 43 @Mock 44 private AudioHelper mHelper; 45 @Mock 46 private TelephonyManager mTelephonyManager; 47 @Mock 48 private AudioManager mAudioManager; 49 @Mock 50 private Vibrator mVibrator; 51 52 private NotificationVolumePreferenceController mController; 53 54 @Before setUp()55 public void setUp() { 56 MockitoAnnotations.initMocks(this); 57 when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); 58 when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager); 59 when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator); 60 mController = new NotificationVolumePreferenceController(mContext, null, null, mHelper); 61 } 62 63 @Test isAvailable_singleVolume_shouldReturnFalse()64 public void isAvailable_singleVolume_shouldReturnFalse() { 65 when(mHelper.isSingleVolume()).thenReturn(true); 66 when(mTelephonyManager.isVoiceCapable()).thenReturn(false); 67 68 assertThat(mController.isAvailable()).isFalse(); 69 } 70 71 @Test isAvailable_voiceCapable_shouldReturnFalse()72 public void isAvailable_voiceCapable_shouldReturnFalse() { 73 when(mHelper.isSingleVolume()).thenReturn(false); 74 when(mTelephonyManager.isVoiceCapable()).thenReturn(true); 75 76 assertThat(mController.isAvailable()).isFalse(); 77 } 78 79 @Test isAvailable_notSingleVolume_notVoiceCapable_shouldReturnTrue()80 public void isAvailable_notSingleVolume_notVoiceCapable_shouldReturnTrue() { 81 when(mHelper.isSingleVolume()).thenReturn(false); 82 when(mTelephonyManager.isVoiceCapable()).thenReturn(false); 83 84 assertThat(mController.isAvailable()).isTrue(); 85 } 86 87 @Test getAudioStream_shouldReturnNotification()88 public void getAudioStream_shouldReturnNotification() { 89 assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_NOTIFICATION); 90 } 91 92 } 93