Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d5fcf86 authored by Josh Tsuji's avatar Josh Tsuji Committed by Android (Google) Code Review
Browse files

Merge "Remove ugly hack now that we're using newer mockito." into main

parents 6d256929 db09257c
Loading
Loading
Loading
Loading
+6 −14
Original line number Diff line number Diff line
@@ -224,14 +224,7 @@ sealed class TransitionInteractor(
    ) {
        if (!KeyguardWmStateRefactor.isEnabled) {
            scope.launch {
                keyguardInteractor.onCameraLaunchDetected
                    .sample(transitionInteractor.finishedKeyguardState)
                    .collect { finishedKeyguardState ->
                        // Other keyguard state transitions may trigger on the first power button
                        // push,
                        // so use the last finishedKeyguardState to determine the overriding FROM
                        // state
                        if (finishedKeyguardState == fromState) {
                keyguardInteractor.onCameraLaunchDetected.filterRelevantKeyguardState().collect {
                    startTransitionTo(
                        toState = KeyguardState.OCCLUDED,
                        modeOnCanceled = TransitionModeOnCanceled.RESET,
@@ -240,7 +233,6 @@ sealed class TransitionInteractor(
            }
        }
    }
    }

    /**
     * Whether we're in the KeyguardState relevant to this From*TransitionInteractor (which we know
+16 −36
Original line number Diff line number Diff line
@@ -754,35 +754,6 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
            coroutineContext.cancelChildren()
        }

    @Test
    fun goneToDreamingLockscreenHosted() =
        testScope.runTest {
            // GIVEN a device that is not dreaming or dozing
            keyguardRepository.setDreamingWithOverlay(false)
            keyguardRepository.setDozeTransitionModel(
                DozeTransitionModel(from = DozeStateModel.DOZE, to = DozeStateModel.FINISH)
            )
            runCurrent()

            // GIVEN a prior transition has run to GONE
            runTransitionAndSetWakefulness(KeyguardState.LOCKSCREEN, KeyguardState.GONE)

            // WHEN the device begins to dream with the lockscreen hosted dream
            keyguardRepository.setDreamingWithOverlay(true)
            keyguardRepository.setIsActiveDreamLockscreenHosted(true)
            advanceTimeBy(100L)

            assertThat(transitionRepository)
                .startedTransition(
                    to = KeyguardState.DREAMING_LOCKSCREEN_HOSTED,
                    from = KeyguardState.GONE,
                    ownerName = "FromGoneTransitionInteractor",
                    animatorAssertion = { it.isNotNull() }
                )

            coroutineContext.cancelChildren()
        }

    @Test
    fun goneToGlanceableHub() =
        testScope.runTest {
@@ -1244,9 +1215,15 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
            keyguardRepository.setKeyguardOccluded(true)
            runCurrent()

            // GIVEN device is docked
            // GIVEN device is docked/communal is available
            dockManager.setIsDocked(true)
            dockManager.setDockEvent(DockManager.STATE_DOCKED)
            val idleTransitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Idle(CommunalScenes.Communal)
                )
            communalInteractor.setTransitionState(idleTransitionState)
            runCurrent()

            // WHEN occlusion ends
            keyguardRepository.setKeyguardOccluded(false)
@@ -1372,6 +1349,8 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {

            // WHEN the keyguard is occluded and device wakes up and is no longer dreaming
            keyguardRepository.setDreaming(false)
            testScheduler.advanceTimeBy(150) // The dreaming signal is debounced.
            runCurrent()
            keyguardRepository.setKeyguardOccluded(true)
            powerInteractor.setAwakeForTest()
            runCurrent()
@@ -1379,7 +1358,7 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
            // THEN a transition to OCCLUDED should occur
            assertThat(transitionRepository)
                .startedTransition(
                    ownerName = "FromDreamingTransitionInteractor",
                    ownerName = "FromDreamingTransitionInteractor(Occluded but no longer dreaming)",
                    from = KeyguardState.DREAMING,
                    to = KeyguardState.OCCLUDED,
                    animatorAssertion = { it.isNotNull() },
@@ -1516,7 +1495,7 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
            // THEN a transition to OCCLUDED should occur
            assertThat(transitionRepository)
                .startedTransition(
                    ownerName = "FromAodTransitionInteractor",
                    ownerName = "FromAodTransitionInteractor(isOccluded = true)",
                    from = KeyguardState.AOD,
                    to = KeyguardState.OCCLUDED,
                    animatorAssertion = { it.isNotNull() },
@@ -1555,7 +1534,8 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
            runTransitionAndSetWakefulness(KeyguardState.AOD, KeyguardState.LOCKSCREEN)
            runCurrent()

            // WHEN the device begins to sleep (first power button press)...
            // WHEN the device begins to sleep (first power button press), which starts
            // LS -> DOZING...
            powerInteractor.setAsleepForTest()
            runCurrent()
            reset(transitionRepository)
@@ -1568,11 +1548,11 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
            }
            runCurrent()

            // THEN a transition from LOCKSCREEN => OCCLUDED should occur
            // THEN a transition from DOZING => OCCLUDED should occur
            assertThat(transitionRepository)
                .startedTransition(
                    ownerName = "FromLockscreenTransitionInteractor",
                    from = KeyguardState.LOCKSCREEN,
                    ownerName = "FromDozingTransitionInteractor",
                    from = KeyguardState.DOZING,
                    to = KeyguardState.OCCLUDED,
                    animatorAssertion = { it.isNotNull() },
                )
+7 −18
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionInfo
import com.android.systemui.keyguard.shared.model.TransitionModeOnCanceled
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.withArgCaptor
import com.google.common.truth.FailureMetadata
import com.google.common.truth.Subject
import com.google.common.truth.Truth
@@ -28,6 +30,8 @@ import com.google.common.truth.Truth.assertAbout
import junit.framework.Assert.assertEquals
import kotlin.test.fail
import org.mockito.Mockito
import org.mockito.Mockito.never
import org.mockito.Mockito.verify

/** [Subject] used to make assertions about a [Mockito.spy] KeyguardTransitionRepository. */
class KeyguardTransitionRepositorySpySubject
@@ -75,34 +79,19 @@ private constructor(
        animatorAssertion: (Subject) -> Unit,
        modeOnCanceled: TransitionModeOnCanceled? = null,
    ) {
        // TODO(b/331799060): Remove this workaround once atest supports mocking suspend functions.
        Mockito.mockingDetails(repository).invocations.forEach { invocation ->
            if (invocation.method.equals(KeyguardTransitionRepository::startTransition.name)) {
                val transitionInfo = invocation.arguments.firstOrNull() as TransitionInfo
        withArgCaptor<TransitionInfo> { verify(repository).startTransition(capture()) }
            .also { transitionInfo ->
                assertEquals(to, transitionInfo.to)
                animatorAssertion.invoke(Truth.assertThat(transitionInfo.animator))
                from?.let { assertEquals(it, transitionInfo.from) }
                ownerName?.let { assertEquals(it, transitionInfo.ownerName) }
                modeOnCanceled?.let { assertEquals(it, transitionInfo.modeOnCanceled) }
                invocation.markVerified()
            }
            }
    }

    /** Verifies that [KeyguardTransitionRepository.startTransition] was never called. */
    suspend fun noTransitionsStarted() {
        // TODO(b/331799060): Remove this workaround once atest supports mocking suspend functions.
        Mockito.mockingDetails(repository).invocations.forEach {
            if (
                it.method.equals(KeyguardTransitionRepository::startTransition.name) &&
                    !it.isVerified
            ) {
                fail(
                    "Expected no transitions started, however this transition was started: " +
                        it.arguments.firstOrNull()
                )
            }
        }
        verify(repository, never()).startTransition(any())
    }

    companion object {