• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.app.NotificationManager;
20 import android.content.ComponentName;
21 import android.content.Context;
22 import android.media.AudioManager;
23 import android.os.Vibrator;
24 import android.telephony.TelephonyManager;
25 
26 import com.android.settings.testutils.SettingsRobolectricTestRunner;
27 import com.android.settings.TestConfig;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.robolectric.annotation.Config;
35 import org.robolectric.shadows.ShadowApplication;
36 
37 import static com.google.common.truth.Truth.assertThat;
38 import static org.mockito.Mockito.when;
39 
40 @RunWith(SettingsRobolectricTestRunner.class)
41 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
42 public class RingVolumePreferenceControllerTest {
43 
44     @Mock
45     private AudioHelper mHelper;
46     @Mock
47     private TelephonyManager mTelephonyManager;
48     @Mock
49     private AudioManager mAudioManager;
50     @Mock
51     private Vibrator mVibrator;
52     @Mock
53     private NotificationManager mNotificationManager;
54     @Mock
55     private ComponentName mSuppressor;
56 
57     private Context mContext;
58     private RingVolumePreferenceController mController;
59 
60     @Before
setUp()61     public void setUp() {
62         MockitoAnnotations.initMocks(this);
63         ShadowApplication shadowContext = ShadowApplication.getInstance();
64         shadowContext.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager);
65         shadowContext.setSystemService(Context.AUDIO_SERVICE, mAudioManager);
66         shadowContext.setSystemService(Context.VIBRATOR_SERVICE, mVibrator);
67         shadowContext.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
68         mContext = shadowContext.getApplicationContext();
69         when(mNotificationManager.getEffectsSuppressor()).thenReturn(mSuppressor);
70         mController = new RingVolumePreferenceController(mContext, null, null, mHelper);
71     }
72 
73     @Test
isAvailable_singleVolume_shouldReturnFalse()74     public void isAvailable_singleVolume_shouldReturnFalse() {
75         when(mHelper.isSingleVolume()).thenReturn(true);
76         when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
77 
78         assertThat(mController.isAvailable()).isFalse();
79     }
80 
81     @Test
isAvailable_notVoiceCapable_shouldReturnFalse()82     public void isAvailable_notVoiceCapable_shouldReturnFalse() {
83         when(mHelper.isSingleVolume()).thenReturn(false);
84         when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
85 
86         assertThat(mController.isAvailable()).isFalse();
87     }
88 
89     @Test
isAvailable_notSingleVolume_VoiceCapable_shouldReturnTrue()90     public void isAvailable_notSingleVolume_VoiceCapable_shouldReturnTrue() {
91         when(mHelper.isSingleVolume()).thenReturn(false);
92         when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
93 
94         assertThat(mController.isAvailable()).isTrue();
95     }
96 
97     @Test
getAudioStream_shouldReturnRing()98     public void getAudioStream_shouldReturnRing() {
99         assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_RING);
100     }
101 
102 }
103