• 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 static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.when;
22 
23 import android.content.Context;
24 import android.content.res.Resources;
25 import android.media.RingtoneManager;
26 import android.media.audio.Flags;
27 import android.platform.test.annotations.DisableFlags;
28 import android.platform.test.annotations.EnableFlags;
29 import android.platform.test.flag.junit.SetFlagsRule;
30 import android.telephony.TelephonyManager;
31 
32 
33 import org.junit.Before;
34 import org.junit.Rule;
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.RobolectricTestRunner;
40 
41 @RunWith(RobolectricTestRunner.class)
42 public class PhoneRingtonePreferenceControllerTest {
43 
44     @Mock
45     private TelephonyManager mTelephonyManager;
46 
47     @Mock
48     private Context mMockContext;
49 
50     @Mock
51     private Resources mMockResources;
52 
53     private PhoneRingtonePreferenceController mController;
54 
55     @Rule
56     public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
57 
58     @Before
setUp()59     public void setUp() {
60         MockitoAnnotations.initMocks(this);
61         when(mMockContext.getResources()).thenReturn(mMockResources);
62         when(mMockContext.getSystemService(
63                 Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
64         mController = new PhoneRingtonePreferenceController(mMockContext);
65     }
66 
67     @Test
68     @DisableFlags(Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION)
isAvailable_notVoiceCapable_shouldReturnFalse()69     public void isAvailable_notVoiceCapable_shouldReturnFalse() {
70         when(mMockResources
71                 .getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
72                 .thenReturn(false);
73         when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
74 
75         assertThat(mController.isAvailable()).isFalse();
76     }
77 
78     @Test
79     @DisableFlags(Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION)
isAvailable_VoiceCapable_shouldReturnTrue()80     public void isAvailable_VoiceCapable_shouldReturnTrue() {
81         when(mMockResources
82                 .getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
83                 .thenReturn(false);
84         when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
85 
86         assertThat(mController.isAvailable()).isTrue();
87     }
88 
89     @Test
90     @EnableFlags(Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION)
isAvailable_vibrationSupported_shouldReturnFalse()91     public void isAvailable_vibrationSupported_shouldReturnFalse() {
92         when(mMockResources
93                 .getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
94                 .thenReturn(true);
95         when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
96 
97         assertThat(mController.isAvailable()).isFalse();
98     }
99 
100     @Test
getRingtoneType_shouldReturnRingtone()101     public void getRingtoneType_shouldReturnRingtone() {
102         assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_RINGTONE);
103     }
104 }
105