• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 org.junit.Assert.assertTrue;
20 import static org.mockito.ArgumentMatchers.any;
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
24 
25 import android.app.NotificationManager;
26 import android.content.Context;
27 
28 import androidx.preference.Preference;
29 
30 import com.android.settingslib.core.lifecycle.Lifecycle;
31 
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.robolectric.RobolectricTestRunner;
38 import org.robolectric.RuntimeEnvironment;
39 import org.robolectric.shadows.ShadowApplication;
40 import org.robolectric.util.ReflectionHelpers;
41 
42 @RunWith(RobolectricTestRunner.class)
43 public final class ZenModeMessagesPreferenceControllerTest {
44 
45     private ZenModeMessagesPreferenceController mController;
46     @Mock
47     private NotificationManager mNotificationManager;
48     @Mock
49     private NotificationManager.Policy mPolicy;
50 
51     private Context mContext;
52     @Mock
53     private ZenModeBackend mBackend;
54 
55     @Before
setup()56     public void setup() {
57         MockitoAnnotations.initMocks(this);
58         ShadowApplication shadowApplication = ShadowApplication.getInstance();
59         shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
60 
61         mContext = RuntimeEnvironment.application;
62         when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
63 
64         mController = new ZenModeMessagesPreferenceController(
65                 mContext, mock(Lifecycle.class), "zen_mode_messages_settings");
66         ReflectionHelpers.setField(mController, "mBackend", mBackend);
67     }
68 
69     @Test
testIsAvailable()70     public void testIsAvailable() {
71         assertTrue(mController.isAvailable());
72     }
73 
74     @Test
testHasSummary()75     public void testHasSummary() {
76         Preference pref = mock(Preference.class);
77         mController.updateState(pref);
78         verify(pref).setSummary(any());
79     }
80 }
81