1 /* 2 * Copyright (C) 2021 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.privacy; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.ArgumentMatchers.any; 22 import static org.mockito.Mockito.when; 23 24 import android.content.Context; 25 26 import androidx.test.core.app.ApplicationProvider; 27 import androidx.test.ext.junit.runners.AndroidJUnit4; 28 29 import com.android.settings.safetycenter.SafetyCenterManagerWrapper; 30 import com.android.settings.security.TopLevelSecurityEntryPreferenceController; 31 32 import org.junit.Before; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.mockito.Mock; 36 import org.mockito.MockitoAnnotations; 37 38 @RunWith(AndroidJUnit4.class) 39 public class TopLevelPrivacyEntryPreferenceControllerTest { 40 41 private static final String PREFERENCE_KEY = "top_level_privacy"; 42 43 private TopLevelPrivacyEntryPreferenceController mTopLevelPrivacyEntryPreferenceController; 44 45 @Mock 46 private SafetyCenterManagerWrapper mSafetyCenterManagerWrapper; 47 48 @Before setUp()49 public void setUp() { 50 MockitoAnnotations.initMocks(this); 51 SafetyCenterManagerWrapper.sInstance = mSafetyCenterManagerWrapper; 52 53 mTopLevelPrivacyEntryPreferenceController = 54 new TopLevelPrivacyEntryPreferenceController( 55 ApplicationProvider.getApplicationContext(), PREFERENCE_KEY); 56 } 57 58 @Test getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable()59 public void getAvailabilityStatus_whenSafetyCenterEnabled_returnsUnavailable() { 60 when(mSafetyCenterManagerWrapper.isEnabled(any(Context.class))).thenReturn(true); 61 62 assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus()) 63 .isEqualTo(TopLevelSecurityEntryPreferenceController.CONDITIONALLY_UNAVAILABLE); 64 } 65 66 @Test getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable()67 public void getAvailabilityStatus_whenSafetyCenterDisabled_returnsAvailable() { 68 when(mSafetyCenterManagerWrapper.isEnabled(any(Context.class))).thenReturn(false); 69 70 assertThat(mTopLevelPrivacyEntryPreferenceController.getAvailabilityStatus()) 71 .isEqualTo(TopLevelSecurityEntryPreferenceController.AVAILABLE); 72 } 73 } 74