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.ArgumentMatchers.anyString;
22 import static org.mockito.Mockito.mock;
23 import static org.mockito.Mockito.never;
24 import static org.mockito.Mockito.verify;
25 
26 import android.content.Context;
27 import android.media.RingtoneManager;
28 import android.provider.Settings;
29 
30 import androidx.preference.Preference;
31 
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.robolectric.RobolectricTestRunner;
36 import org.robolectric.RuntimeEnvironment;
37 
38 @RunWith(RobolectricTestRunner.class)
39 public class RingtonePreferenceControllerBaseTest {
40 
41     private Context mContext;
42 
43     private RingtonePreferenceControllerBase mController;
44 
45     @Before
setUp()46     public void setUp() {
47         mContext = RuntimeEnvironment.application;
48         mController = new RingtonePreferenceControllerBaseTestable(mContext);
49     }
50 
51     @Test
isAlwaysAvailable()52     public void isAlwaysAvailable() {
53         assertThat(mController.isAvailable()).isTrue();
54     }
55 
56     @Test
updateState_shouldSetSummary()57     public void updateState_shouldSetSummary() {
58         Preference preference = mock(Preference.class);
59         Settings.System.putString(mContext.getContentResolver(), Settings.System.RINGTONE,
60                 "content://test/ringtone");
61 
62         mController.updateState(preference);
63 
64         verify(preference).setSummary(anyString());
65     }
66 
67     private class RingtonePreferenceControllerBaseTestable
68             extends RingtonePreferenceControllerBase {
RingtonePreferenceControllerBaseTestable(Context context)69         RingtonePreferenceControllerBaseTestable(Context context) {
70             super(context);
71         }
72 
73         @Override
getPreferenceKey()74         public String getPreferenceKey() {
75             return null;
76         }
77 
78         @Override
getRingtoneType()79         public int getRingtoneType() {
80             return RingtoneManager.TYPE_RINGTONE;
81         }
82     }
83 }
84