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.sim 18 19 import android.content.Context 20 import android.os.UserManager 21 import androidx.test.annotation.UiThreadTest 22 import androidx.test.core.app.ApplicationProvider 23 import androidx.test.ext.junit.runners.AndroidJUnit4 24 import com.android.settingslib.spaprivileged.framework.common.userManager 25 import com.google.common.truth.Truth.assertThat 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.Mock 31 import org.mockito.Spy 32 import org.mockito.junit.MockitoJUnit 33 import org.mockito.junit.MockitoRule 34 import org.mockito.Mockito.`when` as whenever 35 36 @RunWith(AndroidJUnit4::class) 37 @UiThreadTest 38 class SimDialogActivityTest { 39 @get:Rule 40 val mockito: MockitoRule = MockitoJUnit.rule() 41 42 @Spy 43 private val context: Context = ApplicationProvider.getApplicationContext() 44 45 @Mock 46 private lateinit var userManager: UserManager 47 48 private lateinit var activity: SimDialogActivity 49 50 @Before setUpnull51 fun setUp() { 52 activity = MockSimDialogActivity() 53 whenever(context.userManager).thenReturn(userManager) 54 whenever(userManager.isGuestUser).thenReturn(false) 55 whenever(userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) 56 .thenReturn(false) 57 } 58 59 @Test isUiRestricted_normally_returnFalsenull60 fun isUiRestricted_normally_returnFalse() { 61 assertThat(activity.isUiRestricted).isFalse() 62 } 63 64 @Test isUiRestricted_isGuestUser_returnTruenull65 fun isUiRestricted_isGuestUser_returnTrue() { 66 whenever(userManager.isGuestUser).thenReturn(true) 67 68 assertThat(activity.isUiRestricted).isTrue() 69 } 70 71 @Test isUiRestricted_hasUserRestriction_returnTruenull72 fun isUiRestricted_hasUserRestriction_returnTrue() { 73 whenever(userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) 74 .thenReturn(true) 75 76 assertThat(activity.isUiRestricted).isTrue() 77 } 78 79 inner class MockSimDialogActivity : SimDialogActivity() { getApplicationContextnull80 override fun getApplicationContext() = context 81 } 82 } 83