• 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.mockito.Mockito.mock;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
22 
23 import android.app.NotificationManager;
24 import android.content.Context;
25 import android.service.notification.ZenPolicy;
26 
27 import androidx.preference.PreferenceScreen;
28 
29 import com.android.settingslib.core.lifecycle.Lifecycle;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.robolectric.RobolectricTestRunner;
37 import org.robolectric.RuntimeEnvironment;
38 import org.robolectric.shadows.ShadowApplication;
39 import org.robolectric.util.ReflectionHelpers;
40 
41 @RunWith(RobolectricTestRunner.class)
42 public class ZenRuleVisEffectsNonePreferenceControllerTest extends
43         ZenRuleCustomPrefContrTestBase {
44 
45     @Mock
46     private ZenModeBackend mBackend;
47     @Mock
48     private NotificationManager mNotificationManager;
49     @Mock
50     private ZenCustomRadioButtonPreference mockPref;
51     @Mock
52     private PreferenceScreen mScreen;
53 
54     private ZenRuleVisEffectsNonePreferenceController mController;
55     private Context mContext;
56 
57     @Override
getController()58     AbstractZenCustomRulePreferenceController getController() {
59         return mController;
60     }
61 
62     @Before
setup()63     public void setup() {
64         MockitoAnnotations.initMocks(this);
65         ShadowApplication shadowApplication = ShadowApplication.getInstance();
66         shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
67         mContext = RuntimeEnvironment.application;
68         mController = new ZenRuleVisEffectsNonePreferenceController(mContext, mock(Lifecycle.class),
69                 PREF_KEY);
70         ReflectionHelpers.setField(mController, "mBackend", mBackend);
71         when(mBackend.getAutomaticZenRule(RULE_ID)).thenReturn(mRule);
72         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
73         mController.displayPreference(mScreen);
74     }
75 
76     @Test
updateState_noVisEffects()77     public void updateState_noVisEffects() {
78         updateControllerZenPolicy(new ZenPolicy.Builder()
79                 .hideAllVisualEffects()
80                 .build());
81         mController.updateState(mockPref);
82         verify(mockPref).setChecked(true);
83     }
84 
85     @Test
updateState_showAllVisualEffects()86     public void updateState_showAllVisualEffects() {
87         updateControllerZenPolicy(new ZenPolicy.Builder()
88                 .showAllVisualEffects()
89                 .build());
90         mController.updateState(mockPref);
91         verify(mockPref).setChecked(false);
92     }
93 
94     @Test
updateState_custom()95     public void updateState_custom() {
96         updateControllerZenPolicy(new ZenPolicy.Builder()
97                 .showPeeking(true)
98                 .showBadges(false)
99                 .build());
100         mController.updateState(mockPref);
101 
102         verify(mockPref).setChecked(false);
103     }
104 }
105