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