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