1 /* 2 * Copyright (C) 2023 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 com.google.common.truth.Truth.assertThat; 20 21 import android.platform.test.flag.junit.SetFlagsRule; 22 23 import com.android.server.notification.Flags; 24 import com.android.settings.core.BasePreferenceController; 25 26 import org.junit.Before; 27 import org.junit.Rule; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 import org.mockito.MockitoAnnotations; 31 import org.robolectric.RobolectricTestRunner; 32 import org.robolectric.RuntimeEnvironment; 33 34 @RunWith(RobolectricTestRunner.class) 35 public class PoliteNotificationsPreferenceControllerTest { 36 37 @Rule 38 public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); 39 40 private static final String PREFERENCE_KEY = "preference_key"; 41 42 private PoliteNotificationsPreferenceController mController; 43 44 @Before setUp()45 public void setUp() { 46 MockitoAnnotations.initMocks(this); 47 mController = new PoliteNotificationsPreferenceController(RuntimeEnvironment.application, 48 PREFERENCE_KEY); 49 } 50 51 @Test isAvailable_flagEnabled_shouldReturnTrue()52 public void isAvailable_flagEnabled_shouldReturnTrue() { 53 // TODO: b/291907312 - remove feature flags 54 mSetFlagsRule.enableFlags(Flags.FLAG_POLITE_NOTIFICATIONS); 55 assertThat(mController.isAvailable()).isTrue(); 56 assertThat(mController.getAvailabilityStatus()).isEqualTo( 57 BasePreferenceController.AVAILABLE); 58 } 59 60 @Test isAvailable_flagDisabled_shouldReturnFalse()61 public void isAvailable_flagDisabled_shouldReturnFalse() { 62 // TODO: b/291907312 - remove feature flags 63 mSetFlagsRule.disableFlags(Flags.FLAG_POLITE_NOTIFICATIONS); 64 assertThat(mController.isAvailable()).isFalse(); 65 assertThat(mController.getAvailabilityStatus()).isEqualTo( 66 BasePreferenceController.CONDITIONALLY_UNAVAILABLE); 67 } 68 69 } 70