• 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.content.Context;
20 import android.media.RingtoneManager;
21 import android.telephony.TelephonyManager;
22 
23 import com.android.settings.SettingsRobolectricTestRunner;
24 import com.android.settings.TestConfig;
25 
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.Mock;
30 import org.mockito.MockitoAnnotations;
31 import org.robolectric.annotation.Config;
32 import org.robolectric.shadows.ShadowApplication;
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 PhoneRingtonePreferenceControllerTest {
40 
41     @Mock
42     private TelephonyManager mTelephonyManager;
43 
44     private Context mContext;
45     private PhoneRingtonePreferenceController mController;
46 
47     @Before
setUp()48     public void setUp() {
49         MockitoAnnotations.initMocks(this);
50         ShadowApplication shadowContext = ShadowApplication.getInstance();
51         shadowContext.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager);
52         mContext = shadowContext.getApplicationContext();
53         mController = new PhoneRingtonePreferenceController(mContext);
54     }
55 
56     @Test
isAvailable_notVoiceCapable_shouldReturnFalse()57     public void isAvailable_notVoiceCapable_shouldReturnFalse() {
58         when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
59 
60         assertThat(mController.isAvailable()).isFalse();
61     }
62 
63     @Test
isAvailable_VoiceCapable_shouldReturnTrue()64     public void isAvailable_VoiceCapable_shouldReturnTrue() {
65         when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
66 
67         assertThat(mController.isAvailable()).isTrue();
68     }
69 
70     @Test
getRingtoneType_shouldReturnRingtone()71     public void getRingtoneType_shouldReturnRingtone() {
72         assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_RINGTONE);
73     }
74 
75 }
76