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.media.RingtoneManager; 25 import android.telephony.TelephonyManager; 26 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 import org.mockito.Mock; 31 import org.mockito.MockitoAnnotations; 32 import org.robolectric.RobolectricTestRunner; 33 import org.robolectric.RuntimeEnvironment; 34 import org.robolectric.shadows.ShadowApplication; 35 36 @RunWith(RobolectricTestRunner.class) 37 public class PhoneRingtonePreferenceControllerTest { 38 39 @Mock 40 private TelephonyManager mTelephonyManager; 41 42 private Context mContext; 43 private PhoneRingtonePreferenceController mController; 44 45 @Before setUp()46 public void setUp() { 47 MockitoAnnotations.initMocks(this); 48 ShadowApplication shadowContext = ShadowApplication.getInstance(); 49 shadowContext.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager); 50 mContext = RuntimeEnvironment.application; 51 mController = new PhoneRingtonePreferenceController(mContext); 52 } 53 54 @Test isAvailable_notVoiceCapable_shouldReturnFalse()55 public void isAvailable_notVoiceCapable_shouldReturnFalse() { 56 when(mTelephonyManager.isVoiceCapable()).thenReturn(false); 57 58 assertThat(mController.isAvailable()).isFalse(); 59 } 60 61 @Test isAvailable_VoiceCapable_shouldReturnTrue()62 public void isAvailable_VoiceCapable_shouldReturnTrue() { 63 when(mTelephonyManager.isVoiceCapable()).thenReturn(true); 64 65 assertThat(mController.isAvailable()).isTrue(); 66 } 67 68 @Test getRingtoneType_shouldReturnRingtone()69 public void getRingtoneType_shouldReturnRingtone() { 70 assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_RINGTONE); 71 } 72 } 73