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.privatespace; 18 19 import static com.android.settings.core.BasePreferenceController.AVAILABLE; 20 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; 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 27 import android.content.Context; 28 import android.platform.test.flag.junit.SetFlagsRule; 29 30 import androidx.test.core.app.ApplicationProvider; 31 import androidx.test.ext.junit.runners.AndroidJUnit4; 32 33 import com.android.settingslib.widget.FooterPreference; 34 35 import org.junit.Before; 36 import org.junit.Rule; 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 import org.mockito.Mock; 40 import org.mockito.MockitoAnnotations; 41 42 @RunWith(AndroidJUnit4.class) 43 public class PrivateSpaceFooterPreferenceControllerTest { 44 @Mock private Context mContext; 45 @Mock FooterPreference mFooterPreference; 46 @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); 47 private PrivateSpaceFooterPreferenceController mController; 48 49 @Before setUp()50 public void setUp() { 51 MockitoAnnotations.initMocks(this); 52 mContext = ApplicationProvider.getApplicationContext(); 53 final String preferenceKey = "private_space_footer"; 54 55 mController = new PrivateSpaceFooterPreferenceController(mContext, preferenceKey); 56 } 57 58 @Test getAvailabilityStatus_whenFlagsEnabled_returnsAvailable()59 public void getAvailabilityStatus_whenFlagsEnabled_returnsAvailable() { 60 mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES); 61 62 assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); 63 } 64 65 @Test getAvailabilityStatus_whenFlagsDisabled_returnsUnsupportedOnDevice()66 public void getAvailabilityStatus_whenFlagsDisabled_returnsUnsupportedOnDevice() { 67 mSetFlagsRule.disableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES); 68 69 assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); 70 } 71 72 @Test setUpFooter_setsLearnMoreTextAndAction()73 public void setUpFooter_setsLearnMoreTextAndAction() { 74 mSetFlagsRule.enableFlags(android.multiuser.Flags.FLAG_ENABLE_PRIVATE_SPACE_FEATURES); 75 76 mController.setupFooter(mFooterPreference); 77 verify(mFooterPreference).setLearnMoreAction(any()); 78 verify(mFooterPreference).setLearnMoreText("Learn more about private space"); 79 } 80 } 81