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.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 SummarizationManageAppsPreferenceControllerTest { 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 SummarizationManageAppsPreferenceController 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(Flags.FLAG_NM_SUMMARIZATION, Flags.FLAG_NM_SUMMARIZATION_UI); 60 mController = new SummarizationManageAppsPreferenceController(mContext, PREFERENCE_KEY); 61 mController.mBackend.setNm(mInm); 62 } 63 64 @Test isAvailable_flagEnabledNasSupports_shouldReturnTrue()65 public void isAvailable_flagEnabledNasSupports_shouldReturnTrue() { 66 assertThat(mController.isAvailable()).isTrue(); 67 } 68 69 @Test isAvailable_flagEnabledNasDoesNotSupport_shouldReturnFalse()70 public void isAvailable_flagEnabledNasDoesNotSupport_shouldReturnFalse() throws Exception { 71 when(mInm.getUnsupportedAdjustmentTypes()).thenReturn(List.of(KEY_SUMMARIZATION)); 72 assertThat(mController.isAvailable()).isFalse(); 73 } 74 75 @Test isAvailable_flagDisabledNasSupports_shouldReturnFalse()76 public void isAvailable_flagDisabledNasSupports_shouldReturnFalse() { 77 mSetFlagsRule.disableFlags(Flags.FLAG_NM_SUMMARIZATION); 78 mSetFlagsRule.disableFlags(Flags.FLAG_NM_SUMMARIZATION_UI); 79 assertThat(mController.isAvailable()).isFalse(); 80 } 81 } 82