Loading packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryBypassRepositoryTest.kt 0 → 100644 +69 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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.systemui.deviceentry.data.repository import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.runTest import com.android.systemui.statusbar.phone.keyguardBypassController import com.android.systemui.testKosmos import com.android.systemui.util.mockito.withArgCaptor import com.google.common.truth.Truth.assertThat import kotlin.test.Test import org.junit.runner.RunWith import org.mockito.kotlin.verify import org.mockito.kotlin.whenever @SmallTest @RunWith(AndroidJUnit4::class) class DeviceEntryBypassRepositoryTest : SysuiTestCase() { private val kosmos = testKosmos() private val underTest = kosmos.deviceEntryBypassRepositoryImpl @Test fun isBypassEnabled_enabledInController() = kosmos.runTest { whenever(keyguardBypassController.isBypassEnabled).thenAnswer { true } whenever(keyguardBypassController.bypassEnabled).thenAnswer { true } val isBypassEnabled by collectLastValue(underTest.isBypassEnabled) runCurrent() withArgCaptor { verify(keyguardBypassController).registerOnBypassStateChangedListener(capture()) } .onBypassStateChanged(true) assertThat(isBypassEnabled).isTrue() } @Test fun isBypassEnabled_disabledInController() = kosmos.runTest { whenever(keyguardBypassController.isBypassEnabled).thenAnswer { false } whenever(keyguardBypassController.bypassEnabled).thenAnswer { false } val isBypassEnabled by collectLastValue(underTest.isBypassEnabled) runCurrent() withArgCaptor { verify(keyguardBypassController).registerOnBypassStateChangedListener(capture()) } .onBypassStateChanged(false) runCurrent() assertThat(isBypassEnabled).isFalse() } } packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryRepositoryTest.kt +7 −48 Original line number Diff line number Diff line Loading @@ -5,22 +5,18 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.internal.widget.LockPatternUtils import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.statusbar.phone.KeyguardBypassController import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.FakeUserRepository import com.android.systemui.util.mockito.whenever import com.android.systemui.util.mockito.withArgCaptor import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @SmallTest Loading @@ -29,10 +25,8 @@ import org.mockito.MockitoAnnotations class DeviceEntryRepositoryTest : SysuiTestCase() { @Mock private lateinit var lockPatternUtils: LockPatternUtils @Mock private lateinit var keyguardBypassController: KeyguardBypassController private val kosmos = testKosmos() private val testScope = kosmos.testScope private val userRepository = FakeUserRepository() private lateinit var underTest: DeviceEntryRepository Loading @@ -45,17 +39,16 @@ class DeviceEntryRepositoryTest : SysuiTestCase() { underTest = DeviceEntryRepositoryImpl( applicationScope = testScope.backgroundScope, backgroundDispatcher = kosmos.testDispatcher, userRepository = userRepository, lockPatternUtils = lockPatternUtils, keyguardBypassController = keyguardBypassController, ) testScope.runCurrent() kosmos.runCurrent() } @Test fun isLockscreenEnabled() = testScope.runTest { kosmos.runTest { whenever(lockPatternUtils.isLockScreenDisabled(USER_INFOS[0].id)).thenReturn(false) whenever(lockPatternUtils.isLockScreenDisabled(USER_INFOS[1].id)).thenReturn(true) Loading @@ -66,45 +59,11 @@ class DeviceEntryRepositoryTest : SysuiTestCase() { assertThat(underTest.isLockscreenEnabled()).isFalse() } @Test fun isBypassEnabled_disabledInController() = testScope.runTest { whenever(keyguardBypassController.isBypassEnabled).thenAnswer { false } whenever(keyguardBypassController.bypassEnabled).thenAnswer { false } withArgCaptor { verify(keyguardBypassController).registerOnBypassStateChangedListener(capture()) } .onBypassStateChanged(false) runCurrent() assertThat(underTest.isBypassEnabled.value).isFalse() } @Test fun isBypassEnabled_enabledInController() = testScope.runTest { whenever(keyguardBypassController.isBypassEnabled).thenAnswer { true } whenever(keyguardBypassController.bypassEnabled).thenAnswer { true } withArgCaptor { verify(keyguardBypassController).registerOnBypassStateChangedListener(capture()) } .onBypassStateChanged(true) runCurrent() assertThat(underTest.isBypassEnabled.value).isTrue() } companion object { private val USER_INFOS = listOf( UserInfo( /* id= */ 100, /* name= */ "First user", /* flags= */ 0, ), UserInfo( /* id= */ 101, /* name= */ "Second user", /* flags= */ 0, ), UserInfo(/* id= */ 100, /* name= */ "First user", /* flags= */ 0), UserInfo(/* id= */ 101, /* name= */ "Second user", /* flags= */ 0), ) } } packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryBypassInteractorTest.kt 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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.systemui.deviceentry.domain.interactor import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryBypassRepository import com.android.systemui.kosmos.runTest import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class DeviceEntryBypassInteractorTest : SysuiTestCase() { private val kosmos = testKosmos() private val underTest = kosmos.deviceEntryBypassInteractor @Test fun isBypassEnabled_enabledInRepository_true() = kosmos.runTest { fakeDeviceEntryBypassRepository.setBypassEnabled(true) assertThat(underTest.isBypassEnabled.value).isTrue() } @Test fun isBypassEnabled_disabledInRepository_false() = kosmos.runTest { fakeDeviceEntryBypassRepository.setBypassEnabled(false) assertThat(underTest.isBypassEnabled.value).isFalse() } } packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorTest.kt +0 −14 Original line number Diff line number Diff line Loading @@ -310,13 +310,6 @@ class DeviceEntryInteractorTest : SysuiTestCase() { assertThat(underTest.isAuthenticationRequired()).isFalse() } @Test fun isBypassEnabled_enabledInRepository_true() = testScope.runTest { kosmos.fakeDeviceEntryRepository.setBypassEnabled(true) assertThat(underTest.isBypassEnabled.value).isTrue() } @Test fun showOrUnlockDevice_notLocked_switchesToGoneScene() = testScope.runTest { Loading Loading @@ -409,13 +402,6 @@ class DeviceEntryInteractorTest : SysuiTestCase() { assertThat(currentScene).isEqualTo(Scenes.Lockscreen) } @Test fun isBypassEnabled_disabledInRepository_false() = testScope.runTest { kosmos.fakeDeviceEntryRepository.setBypassEnabled(false) assertThat(underTest.isBypassEnabled.value).isFalse() } @Test fun successfulAuthenticationChallengeAttempt_updatesIsUnlockedState() = testScope.runTest { Loading packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorTest.kt +3 −3 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository import com.android.systemui.authentication.shared.model.AuthenticationMethodModel import com.android.systemui.coroutines.collectLastValue import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryRepository import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryBypassRepository import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason import com.android.systemui.deviceentry.shared.model.DeviceUnlockSource import com.android.systemui.flags.fakeSystemPropertiesHelper Loading Loading @@ -175,7 +175,7 @@ class DeviceUnlockedInteractorTest : SysuiTestCase() { kosmos.powerInteractor.setAwakeForTest() kosmos.fakeDeviceEntryFaceAuthRepository.isAuthenticated.value = true kosmos.fakeDeviceEntryRepository.setBypassEnabled(true) kosmos.fakeDeviceEntryBypassRepository.setBypassEnabled(true) runCurrent() assertThat(deviceUnlockStatus?.isUnlocked).isTrue() Loading @@ -189,7 +189,7 @@ class DeviceUnlockedInteractorTest : SysuiTestCase() { val deviceUnlockStatus by collectLastValue(underTest.deviceUnlockStatus) kosmos.fakeDeviceEntryFaceAuthRepository.isAuthenticated.value = true kosmos.fakeDeviceEntryRepository.setBypassEnabled(false) kosmos.fakeDeviceEntryBypassRepository.setBypassEnabled(false) runCurrent() assertThat(deviceUnlockStatus?.isUnlocked).isTrue() Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryBypassRepositoryTest.kt 0 → 100644 +69 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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.systemui.deviceentry.data.repository import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.runTest import com.android.systemui.statusbar.phone.keyguardBypassController import com.android.systemui.testKosmos import com.android.systemui.util.mockito.withArgCaptor import com.google.common.truth.Truth.assertThat import kotlin.test.Test import org.junit.runner.RunWith import org.mockito.kotlin.verify import org.mockito.kotlin.whenever @SmallTest @RunWith(AndroidJUnit4::class) class DeviceEntryBypassRepositoryTest : SysuiTestCase() { private val kosmos = testKosmos() private val underTest = kosmos.deviceEntryBypassRepositoryImpl @Test fun isBypassEnabled_enabledInController() = kosmos.runTest { whenever(keyguardBypassController.isBypassEnabled).thenAnswer { true } whenever(keyguardBypassController.bypassEnabled).thenAnswer { true } val isBypassEnabled by collectLastValue(underTest.isBypassEnabled) runCurrent() withArgCaptor { verify(keyguardBypassController).registerOnBypassStateChangedListener(capture()) } .onBypassStateChanged(true) assertThat(isBypassEnabled).isTrue() } @Test fun isBypassEnabled_disabledInController() = kosmos.runTest { whenever(keyguardBypassController.isBypassEnabled).thenAnswer { false } whenever(keyguardBypassController.bypassEnabled).thenAnswer { false } val isBypassEnabled by collectLastValue(underTest.isBypassEnabled) runCurrent() withArgCaptor { verify(keyguardBypassController).registerOnBypassStateChangedListener(capture()) } .onBypassStateChanged(false) runCurrent() assertThat(isBypassEnabled).isFalse() } }
packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/data/repository/DeviceEntryRepositoryTest.kt +7 −48 Original line number Diff line number Diff line Loading @@ -5,22 +5,18 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.internal.widget.LockPatternUtils import com.android.systemui.SysuiTestCase import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.statusbar.phone.KeyguardBypassController import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.FakeUserRepository import com.android.systemui.util.mockito.whenever import com.android.systemui.util.mockito.withArgCaptor import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.runBlocking import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @SmallTest Loading @@ -29,10 +25,8 @@ import org.mockito.MockitoAnnotations class DeviceEntryRepositoryTest : SysuiTestCase() { @Mock private lateinit var lockPatternUtils: LockPatternUtils @Mock private lateinit var keyguardBypassController: KeyguardBypassController private val kosmos = testKosmos() private val testScope = kosmos.testScope private val userRepository = FakeUserRepository() private lateinit var underTest: DeviceEntryRepository Loading @@ -45,17 +39,16 @@ class DeviceEntryRepositoryTest : SysuiTestCase() { underTest = DeviceEntryRepositoryImpl( applicationScope = testScope.backgroundScope, backgroundDispatcher = kosmos.testDispatcher, userRepository = userRepository, lockPatternUtils = lockPatternUtils, keyguardBypassController = keyguardBypassController, ) testScope.runCurrent() kosmos.runCurrent() } @Test fun isLockscreenEnabled() = testScope.runTest { kosmos.runTest { whenever(lockPatternUtils.isLockScreenDisabled(USER_INFOS[0].id)).thenReturn(false) whenever(lockPatternUtils.isLockScreenDisabled(USER_INFOS[1].id)).thenReturn(true) Loading @@ -66,45 +59,11 @@ class DeviceEntryRepositoryTest : SysuiTestCase() { assertThat(underTest.isLockscreenEnabled()).isFalse() } @Test fun isBypassEnabled_disabledInController() = testScope.runTest { whenever(keyguardBypassController.isBypassEnabled).thenAnswer { false } whenever(keyguardBypassController.bypassEnabled).thenAnswer { false } withArgCaptor { verify(keyguardBypassController).registerOnBypassStateChangedListener(capture()) } .onBypassStateChanged(false) runCurrent() assertThat(underTest.isBypassEnabled.value).isFalse() } @Test fun isBypassEnabled_enabledInController() = testScope.runTest { whenever(keyguardBypassController.isBypassEnabled).thenAnswer { true } whenever(keyguardBypassController.bypassEnabled).thenAnswer { true } withArgCaptor { verify(keyguardBypassController).registerOnBypassStateChangedListener(capture()) } .onBypassStateChanged(true) runCurrent() assertThat(underTest.isBypassEnabled.value).isTrue() } companion object { private val USER_INFOS = listOf( UserInfo( /* id= */ 100, /* name= */ "First user", /* flags= */ 0, ), UserInfo( /* id= */ 101, /* name= */ "Second user", /* flags= */ 0, ), UserInfo(/* id= */ 100, /* name= */ "First user", /* flags= */ 0), UserInfo(/* id= */ 101, /* name= */ "Second user", /* flags= */ 0), ) } }
packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryBypassInteractorTest.kt 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 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.systemui.deviceentry.domain.interactor import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryBypassRepository import com.android.systemui.kosmos.runTest import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import org.junit.Test import org.junit.runner.RunWith @SmallTest @RunWith(AndroidJUnit4::class) class DeviceEntryBypassInteractorTest : SysuiTestCase() { private val kosmos = testKosmos() private val underTest = kosmos.deviceEntryBypassInteractor @Test fun isBypassEnabled_enabledInRepository_true() = kosmos.runTest { fakeDeviceEntryBypassRepository.setBypassEnabled(true) assertThat(underTest.isBypassEnabled.value).isTrue() } @Test fun isBypassEnabled_disabledInRepository_false() = kosmos.runTest { fakeDeviceEntryBypassRepository.setBypassEnabled(false) assertThat(underTest.isBypassEnabled.value).isFalse() } }
packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceEntryInteractorTest.kt +0 −14 Original line number Diff line number Diff line Loading @@ -310,13 +310,6 @@ class DeviceEntryInteractorTest : SysuiTestCase() { assertThat(underTest.isAuthenticationRequired()).isFalse() } @Test fun isBypassEnabled_enabledInRepository_true() = testScope.runTest { kosmos.fakeDeviceEntryRepository.setBypassEnabled(true) assertThat(underTest.isBypassEnabled.value).isTrue() } @Test fun showOrUnlockDevice_notLocked_switchesToGoneScene() = testScope.runTest { Loading Loading @@ -409,13 +402,6 @@ class DeviceEntryInteractorTest : SysuiTestCase() { assertThat(currentScene).isEqualTo(Scenes.Lockscreen) } @Test fun isBypassEnabled_disabledInRepository_false() = testScope.runTest { kosmos.fakeDeviceEntryRepository.setBypassEnabled(false) assertThat(underTest.isBypassEnabled.value).isFalse() } @Test fun successfulAuthenticationChallengeAttempt_updatesIsUnlockedState() = testScope.runTest { Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/deviceentry/domain/interactor/DeviceUnlockedInteractorTest.kt +3 −3 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository import com.android.systemui.authentication.shared.model.AuthenticationMethodModel import com.android.systemui.coroutines.collectLastValue import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryRepository import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryBypassRepository import com.android.systemui.deviceentry.shared.model.DeviceEntryRestrictionReason import com.android.systemui.deviceentry.shared.model.DeviceUnlockSource import com.android.systemui.flags.fakeSystemPropertiesHelper Loading Loading @@ -175,7 +175,7 @@ class DeviceUnlockedInteractorTest : SysuiTestCase() { kosmos.powerInteractor.setAwakeForTest() kosmos.fakeDeviceEntryFaceAuthRepository.isAuthenticated.value = true kosmos.fakeDeviceEntryRepository.setBypassEnabled(true) kosmos.fakeDeviceEntryBypassRepository.setBypassEnabled(true) runCurrent() assertThat(deviceUnlockStatus?.isUnlocked).isTrue() Loading @@ -189,7 +189,7 @@ class DeviceUnlockedInteractorTest : SysuiTestCase() { val deviceUnlockStatus by collectLastValue(underTest.deviceUnlockStatus) kosmos.fakeDeviceEntryFaceAuthRepository.isAuthenticated.value = true kosmos.fakeDeviceEntryRepository.setBypassEnabled(false) kosmos.fakeDeviceEntryBypassRepository.setBypassEnabled(false) runCurrent() assertThat(deviceUnlockStatus?.isUnlocked).isTrue() Loading