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

Commit b9eba49b authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "[69/n] Improved Tests readability" into main

parents d5f3b81c 3f18e6fb
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.desktopmode.DesktopRepository
import com.android.wm.shell.util.testLetterboxDependenciesHelper
import java.util.function.Consumer
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
@@ -45,7 +47,7 @@ class DefaultLetterboxDependenciesHelperTest : ShellTestCase() {
                inputChange { }
                r.configureDesktopRepository(isAnyDeskActive = false)
                validateIsDesktopWindowingAction { shouldDestroy ->
                    assert(!shouldDestroy)
                    assertFalse(shouldDestroy)
                }
            }
        }
@@ -58,7 +60,7 @@ class DefaultLetterboxDependenciesHelperTest : ShellTestCase() {
                inputChange { }
                r.configureDesktopRepository(isAnyDeskActive = true)
                validateIsDesktopWindowingAction { shouldDestroy ->
                    assert(shouldDestroy)
                    assertTrue(shouldDestroy)
                }
            }
        }
+23 −19
Original line number Diff line number Diff line
@@ -22,9 +22,14 @@ import androidx.test.filters.SmallTest
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.compatui.letterbox.lifecycle.FakeLetterboxLifecycleEventFactory.Companion.FAKE_EVENT
import com.android.wm.shell.util.testLetterboxLifecycleEventFactory
import java.util.function.Consumer
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import java.util.function.Consumer

/**
 * Tests for [MultiLetterboxLifecycleEventFactory].
@@ -47,15 +52,15 @@ class MultiLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                    // No specific Change initialization required.
                }
                validateCanHandle { canHandler ->
                    assert(canHandler == true)
                    assertTrue(canHandler)
                    r.assertOnCandidate(0) { f ->
                        assert(f.canHandleInvokeTimes == 1)
                        assertEquals(1, f.canHandleInvokeTimes)
                    }
                    r.assertOnCandidate(1) { f ->
                        assert(f.canHandleInvokeTimes == 1)
                        assertEquals(1, f.canHandleInvokeTimes)
                    }
                    r.assertOnCandidate(2) { f ->
                        assert(f.canHandleInvokeTimes == 0)
                        assertEquals(0, f.canHandleInvokeTimes)
                    }
                }
            }
@@ -73,7 +78,7 @@ class MultiLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                    // No specific Change initialization required.
                }
                validateCanHandle { canHandler ->
                    assert(canHandler == false)
                    assertFalse(canHandler)
                }
            }
        }
@@ -90,11 +95,11 @@ class MultiLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                    // No specific Change initialization required.
                }
                validateCreateLifecycleEvent { event ->
                    assert(event == null)
                    assertNull(event)
                    for (pos in 0..2) {
                        r.assertOnCandidate(pos) { f ->
                            assert(f.canHandleInvokeTimes == 1)
                            assert(f.createLifecycleEventInvokeTimes == 0)
                            assertEquals(1, f.canHandleInvokeTimes)
                            assertEquals(0, f.createLifecycleEventInvokeTimes)
                        }
                    }
                }
@@ -119,21 +124,21 @@ class MultiLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                    // No specific Change initialization required.
                }
                validateCreateLifecycleEvent { event ->
                    assert(event != null)
                    assertNotNull(event)
                    r.assertOnCandidate(0) { f ->
                        assert(f.canHandleInvokeTimes == 1)
                        assert(f.createLifecycleEventInvokeTimes == 0)
                        assertEquals(1, f.canHandleInvokeTimes)
                        assertEquals(0, f.createLifecycleEventInvokeTimes)
                    }
                    r.assertOnCandidate(1) { f ->
                        assert(f.canHandleInvokeTimes == 1)
                        assert(f.createLifecycleEventInvokeTimes == 1)
                        assertEquals(1, f.canHandleInvokeTimes)
                        assertEquals(1, f.createLifecycleEventInvokeTimes)
                    }
                    r.assertOnCandidate(2) { f ->
                        assert(f.canHandleInvokeTimes == 0)
                        assert(f.createLifecycleEventInvokeTimes == 0)
                        assertEquals(0, f.canHandleInvokeTimes)
                        assertEquals(0, f.createLifecycleEventInvokeTimes)
                    }
                    assert(event?.taskId == 30)
                    assert(event?.taskBounds == Rect(1, 2, 3, 4))
                    assertEquals(30, event.taskId)
                    assertEquals(Rect(1, 2, 3, 4), event.taskBounds)
                }
            }
        }
@@ -152,7 +157,6 @@ class MultiLetterboxLifecycleEventFactoryTest : ShellTestCase() {
     */
    class LetterboxLifecycleControllerImplRobotTest {


        private val candidates = mutableListOf<FakeLetterboxLifecycleEventFactory>()

        fun getLetterboxLifecycleEventFactory(): () -> LetterboxLifecycleEventFactory = {
+13 −15
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ import androidx.test.filters.SmallTest
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.util.testLetterboxLifecycleEventFactory
import java.util.function.Consumer
import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertTrue
import org.junit.Test
import org.junit.runner.RunWith

@@ -44,10 +47,10 @@ class SkipLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                    mode = TRANSIT_CLOSE
                }
                validateCanHandle { canHandle ->
                    assert(canHandle)
                    assertTrue(canHandle)
                }
                validateCreateLifecycleEvent { event ->
                    assert(event == null)
                    assertNull(event)
                }
            }
        }
@@ -64,38 +67,37 @@ class SkipLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                    }
                }
                validateCanHandle { canHandle ->
                    assert(canHandle)
                    assertTrue(canHandle)
                }
                validateCreateLifecycleEvent { event ->
                    assert(event == null)
                    assertNull(event)
                }
            }
        }
    }

    @Test
    fun `Factory is skipped when Change is not closing for a Task which is NOT a leaf`() {
    fun `Factory is active when Change is not closing for a Task which is NOT a leaf`() {
        runTestScenario { r ->
            testLetterboxLifecycleEventFactory(r.getLetterboxLifecycleEventFactory()) {
                inputChange {
                    mode = TRANSIT_OPEN
                    runningTaskInfo { ti ->
                        ti.appCompatTaskInfo.setIsLeafTask(true)
                        ti.appCompatTaskInfo.setIsLeafTask(false)
                    }
                }
                validateCanHandle { canHandle ->
                    assert(!canHandle)
                    assertTrue(canHandle)
                }
                validateCreateLifecycleEvent { event ->
                    assert(event != null)
                    assert(event?.type == LetterboxLifecycleEventType.NONE)
                    assertNull(event)
                }
            }
        }
    }

    @Test
    fun `Factory is skipped when Change is not closing for an Activity Transition`() {
    fun `Factory is NOT active when Change is not closing for an Activity Transition`() {
        runTestScenario { r ->
            testLetterboxLifecycleEventFactory(r.getLetterboxLifecycleEventFactory()) {
                inputChange {
@@ -105,11 +107,7 @@ class SkipLetterboxLifecycleEventFactoryTest : ShellTestCase() {
                    }
                }
                validateCanHandle { canHandle ->
                    assert(!canHandle)
                }
                validateCreateLifecycleEvent { event ->
                    assert(event != null)
                    assert(event?.type == LetterboxLifecycleEventType.NONE)
                    assertFalse(canHandle)
                }
            }
        }
+7 −4
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.util.testTaskAppearedListener
import com.android.wm.shell.util.testTaskVanishedListener
import java.util.function.Consumer
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
@@ -78,8 +81,8 @@ class LetterboxTaskListenerAdapterTest : ShellTestCase() {
                leash { leashTest }
                validateOnTaskAppeared {
                    r.validateItem(10) { item ->
                        assert(item?.containerLeash == leashTest)
                        assert(item?.containerToken == tokenTest)
                        assertEquals(leashTest, item?.containerLeash)
                        assertEquals(tokenTest, item?.containerToken)
                    }
                }
            }
@@ -99,7 +102,7 @@ class LetterboxTaskListenerAdapterTest : ShellTestCase() {
                leash { leashTest }
                validateOnTaskAppeared {
                    r.validateItem(10) { item ->
                        assert(item != null)
                        assertNotNull(item)
                    }
                }
            }
@@ -110,7 +113,7 @@ class LetterboxTaskListenerAdapterTest : ShellTestCase() {
                }
                validateOnTaskVanished {
                    r.validateItem(10) { item ->
                        assert(item == null)
                        assertNull(item)
                    }
                }
            }