• 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 import static org.mockito.Matchers.anyString;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.verify;
23 
24 import android.content.Context;
25 import android.media.RingtoneManager;
26 import android.support.v7.preference.Preference;
27 
28 import com.android.settings.testutils.SettingsRobolectricTestRunner;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 
36 @RunWith(SettingsRobolectricTestRunner.class)
37 public class RingtonePreferenceControllerBaseTest {
38 
39     @Mock
40     private Context mContext;
41 
42     private RingtonePreferenceControllerBase mController;
43 
44     @Before
setUp()45     public void setUp() {
46         MockitoAnnotations.initMocks(this);
47         mController = new RingtonePreferenceControllerBaseTestable(mContext);
48     }
49 
50     @Test
isAlwaysAvailable()51     public void isAlwaysAvailable() {
52         assertThat(mController.isAvailable()).isTrue();
53     }
54 
55     @Test
updateState_shouldSetSummary()56     public void updateState_shouldSetSummary() {
57         Preference preference = mock(Preference.class);
58 
59         mController.updateState(preference);
60 
61         verify(preference).setSummary(anyString());
62     }
63 
64     private class RingtonePreferenceControllerBaseTestable
65         extends RingtonePreferenceControllerBase {
RingtonePreferenceControllerBaseTestable(Context context)66         RingtonePreferenceControllerBaseTestable(Context context) {
67             super(context);
68         }
69 
70         @Override
getPreferenceKey()71         public String getPreferenceKey() {
72             return null;
73         }
74 
75         @Override
getRingtoneType()76         public int getRingtoneType() {
77             return RingtoneManager.TYPE_RINGTONE;
78         }
79     }
80 }
81