diff --git a/tests/unit/src/com/android/settings/sim/SimDialogActivityTest.java b/tests/unit/src/com/android/settings/sim/SimDialogActivityTest.java deleted file mode 100644 index a2320341c62..00000000000 --- a/tests/unit/src/com/android/settings/sim/SimDialogActivityTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.sim; - -import static android.os.UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.os.UserManager; - -import androidx.test.annotation.UiThreadTest; -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Spy; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -@RunWith(AndroidJUnit4.class) -@UiThreadTest -public class SimDialogActivityTest { - @Rule - public final MockitoRule mMockitoRule = MockitoJUnit.rule(); - @Spy - private final Context mContext = ApplicationProvider.getApplicationContext(); - @Mock - private UserManager mUserManager; - - private MockSimDialogActivity mActivity; - - @Before - public void setUp() { - when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager); - when(mUserManager.isGuestUser()).thenReturn(false); - when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(false); - - mActivity = new MockSimDialogActivity(); - } - - @Test - public void isUiRestricted_normally_returnFalse() { - assertThat(mActivity.isUiRestricted()).isFalse(); - } - - @Test - public void isUiRestricted_isGuestUser_returnTrue() { - when(mUserManager.isGuestUser()).thenReturn(true); - - assertThat(mActivity.isUiRestricted()).isTrue(); - } - - @Test - public void isUiRestricted_hasUserRestriction_returnTrue() { - when(mUserManager.hasUserRestriction(DISALLOW_CONFIG_MOBILE_NETWORKS)).thenReturn(true); - - assertThat(mActivity.isUiRestricted()).isTrue(); - } - - public class MockSimDialogActivity extends SimDialogActivity { - @Override - public Context getApplicationContext() { - return mContext; - } - } -} diff --git a/tests/unit/src/com/android/settings/sim/SimDialogActivityTest.kt b/tests/unit/src/com/android/settings/sim/SimDialogActivityTest.kt new file mode 100644 index 00000000000..9546d69c5bc --- /dev/null +++ b/tests/unit/src/com/android/settings/sim/SimDialogActivityTest.kt @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.sim + +import android.content.Context +import android.os.UserManager +import androidx.test.annotation.UiThreadTest +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.android.settingslib.spaprivileged.framework.common.userManager +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Spy +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule +import org.mockito.Mockito.`when` as whenever + +@RunWith(AndroidJUnit4::class) +@UiThreadTest +class SimDialogActivityTest { + @get:Rule + val mockito: MockitoRule = MockitoJUnit.rule() + + @Spy + private val context: Context = ApplicationProvider.getApplicationContext() + + @Mock + private lateinit var userManager: UserManager + + private var activity = MockSimDialogActivity() + + @Before + fun setUp() { + whenever(context.userManager).thenReturn(userManager) + whenever(userManager.isGuestUser).thenReturn(false) + whenever(userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) + .thenReturn(false) + } + + @Test + fun isUiRestricted_normally_returnFalse() { + assertThat(activity.isUiRestricted).isFalse() + } + + @Test + fun isUiRestricted_isGuestUser_returnTrue() { + whenever(userManager.isGuestUser).thenReturn(true) + + assertThat(activity.isUiRestricted).isTrue() + } + + @Test + fun isUiRestricted_hasUserRestriction_returnTrue() { + whenever(userManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) + .thenReturn(true) + + assertThat(activity.isUiRestricted).isTrue() + } + + inner class MockSimDialogActivity : SimDialogActivity() { + override fun getApplicationContext() = context + } +}