• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 static com.android.settings.core.BasePreferenceController.AVAILABLE;
20 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 
25 import static org.mockito.Mockito.when;
26 
27 import android.content.Context;
28 import android.media.AudioManager;
29 
30 import com.android.settings.R;
31 import com.android.settings.testutils.SettingsRobolectricTestRunner;
32 import com.android.settings.testutils.shadow.ShadowAudioManager;
33 
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.Mock;
38 import org.mockito.MockitoAnnotations;
39 import org.robolectric.RuntimeEnvironment;
40 import org.robolectric.annotation.Config;
41 
42 @RunWith(SettingsRobolectricTestRunner.class)
43 @Config(shadows = {ShadowAudioManager.class})
44 public class CallVolumePreferenceControllerTest {
45     private static final String TEST_KEY = "Test_Key";
46 
47     @Mock
48     private AudioHelper mHelper;
49 
50     private Context mContext;
51     private CallVolumePreferenceController mController;
52     private ShadowAudioManager mShadowAudioManager;
53 
54     @Before
setUp()55     public void setUp() {
56         MockitoAnnotations.initMocks(this);
57         mContext = RuntimeEnvironment.application;
58         mController = new CallVolumePreferenceController(mContext, TEST_KEY);
59         mController.setAudioHelper(mHelper);
60         mShadowAudioManager = ShadowAudioManager.getShadow();
61     }
62 
63     @Test
getAvailabilityStatus_singleVolume_shouldReturnDisable()64     public void getAvailabilityStatus_singleVolume_shouldReturnDisable() {
65         when(mHelper.isSingleVolume()).thenReturn(true);
66 
67         assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
68     }
69 
70     @Test
getAvailabilityStatus_notSingleVolume_shouldReturnAvailable()71     public void getAvailabilityStatus_notSingleVolume_shouldReturnAvailable() {
72         when(mHelper.isSingleVolume()).thenReturn(false);
73 
74         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
75     }
76 
77     @Test
getMuteIcon_shouldEqualToOriginalIcon()78     public void getMuteIcon_shouldEqualToOriginalIcon() {
79         assertThat(mController.getMuteIcon()).isEqualTo(R.drawable.ic_local_phone_24_lib);
80     }
81 
82     @Test
getAudioStream_onBluetoothScoOff_shouldEqualToStreamVoiceCall()83     public void getAudioStream_onBluetoothScoOff_shouldEqualToStreamVoiceCall() {
84         mShadowAudioManager.setBluetoothScoOn(false);
85 
86         assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_VOICE_CALL);
87     }
88 
89     @Test
getAudioStream_onBluetoothScoOn_shouldEqualToStreamBtSco()90     public void getAudioStream_onBluetoothScoOn_shouldEqualToStreamBtSco() {
91         mShadowAudioManager.setBluetoothScoOn(true);
92 
93         assertThat(mController.getAudioStream()).isEqualTo(AudioManager.STREAM_BLUETOOTH_SCO);
94     }
95 
96     @Test
isSliceableCorrectKey_returnsTrue()97     public void isSliceableCorrectKey_returnsTrue() {
98         final CallVolumePreferenceController controller =
99         new CallVolumePreferenceController(mContext,"call_volume");
100         assertThat(controller.isSliceable()).isTrue();
101     }
102 
103     @Test
isSliceableIncorrectKey_returnsFalse()104     public void isSliceableIncorrectKey_returnsFalse() {
105         final CallVolumePreferenceController controller =
106         new CallVolumePreferenceController(mContext, "bad_key");
107         assertThat(controller.isSliceable()).isFalse();
108     }
109 }
110