• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 android.service.notification.Adjustment.KEY_IMPORTANCE;
20 import static android.service.notification.Adjustment.KEY_TYPE;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.when;
26 
27 import android.app.Flags;
28 import android.app.INotificationManager;
29 import android.content.Context;
30 import android.platform.test.flag.junit.SetFlagsRule;
31 
32 import org.junit.Before;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 import org.robolectric.RobolectricTestRunner;
39 import org.robolectric.RuntimeEnvironment;
40 
41 import java.util.List;
42 
43 @RunWith(RobolectricTestRunner.class)
44 public class BundlePreferenceControllerTest {
45     @Rule
46     public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
47 
48     private static final String PREFERENCE_KEY = "preference_key";
49 
50     private Context mContext;
51     BundlePreferenceController mController;
52     @Mock
53     INotificationManager mInm;
54 
55     @Before
setUp()56     public void setUp() {
57         MockitoAnnotations.initMocks(this);
58         mContext = RuntimeEnvironment.application;
59         mSetFlagsRule.enableFlags(
60                 android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION,
61                 Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI);
62         mController = new BundlePreferenceController(mContext, PREFERENCE_KEY);
63         mController.mBackend.setNm(mInm);
64     }
65 
66     @Test
isAvailable_flagEnabledNasSupports_shouldReturnTrue()67     public void isAvailable_flagEnabledNasSupports_shouldReturnTrue() {
68         assertThat(mController.isAvailable()).isTrue();
69     }
70 
71     @Test
isAvailable_flagEnabledNasDoesNotSupport_shouldReturnFalse()72     public void isAvailable_flagEnabledNasDoesNotSupport_shouldReturnFalse() throws Exception {
73         when(mInm.getUnsupportedAdjustmentTypes()).thenReturn(List.of(KEY_TYPE));
74         assertThat(mController.isAvailable()).isFalse();
75     }
76 
77     @Test
isAvailable_flagDisabledNasSupports_shouldReturnFalse()78     public void isAvailable_flagDisabledNasSupports_shouldReturnFalse() {
79         mSetFlagsRule.disableFlags(Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI);
80         assertThat(mController.isAvailable()).isFalse();
81     }
82 
83     @Test
getSummary()84     public void getSummary() throws Exception {
85         when(mInm.getAllowedAssistantAdjustments(any())).thenReturn(List.of(KEY_TYPE));
86         assertThat(mController.getSummary()).isEqualTo("On");
87 
88         when(mInm.getAllowedAssistantAdjustments(any())).thenReturn(List.of(KEY_IMPORTANCE));
89         assertThat(mController.getSummary()).isEqualTo("Off");
90     }
91 }
92