• 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_SUMMARIZATION;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import static org.mockito.Mockito.when;
24 
25 import android.app.Flags;
26 import android.app.INotificationManager;
27 import android.content.Context;
28 import android.platform.test.flag.junit.SetFlagsRule;
29 import android.service.notification.Adjustment;
30 
31 import org.junit.Before;
32 import org.junit.Rule;
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 
40 import java.util.List;
41 
42 @RunWith(RobolectricTestRunner.class)
43 public class BundleManageAppsPreferenceControllerTest {
44     @Rule
45     public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
46 
47     private static final String PREFERENCE_KEY = "preference_key";
48 
49     private Context mContext;
50     BundleManageAppsPreferenceController mController;
51     @Mock
52     INotificationManager mInm;
53 
54     @Before
setUp()55     public void setUp() {
56         MockitoAnnotations.initMocks(this);
57         mContext = RuntimeEnvironment.application;
58         mSetFlagsRule.enableFlags(Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI);
59         mController = new BundleManageAppsPreferenceController(mContext, PREFERENCE_KEY);
60         mController.mBackend.setNm(mInm);
61     }
62 
63     @Test
isAvailable_flagEnabledNasSupports_shouldReturnTrue()64     public void isAvailable_flagEnabledNasSupports_shouldReturnTrue() {
65         assertThat(mController.isAvailable()).isTrue();
66     }
67 
68     @Test
isAvailable_flagEnabledNasDoesNotSupport_shouldReturnFalse()69     public void isAvailable_flagEnabledNasDoesNotSupport_shouldReturnFalse() throws Exception {
70         when(mInm.getUnsupportedAdjustmentTypes()).thenReturn(List.of(Adjustment.KEY_TYPE));
71         assertThat(mController.isAvailable()).isFalse();
72     }
73 
74     @Test
isAvailable_flagDisabledNasSupports_shouldReturnFalse()75     public void isAvailable_flagDisabledNasSupports_shouldReturnFalse() {
76         mSetFlagsRule.disableFlags(Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI);
77         assertThat(mController.isAvailable()).isFalse();
78     }
79 }
80