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

Commit 4bdcf7e9 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Defer complex object creation until used by tests.

As part of supporting SysUI multivalentTests under the new Ravenwood
testing environment, tests need to be more careful about only
creating and interacting with "complex" objects when they're actually
needed by a test.  Attempting interactions during <init> or <clinit>
of the overall test class fails on Ravenwood when these complex
objects aren't yet supported, and they throw an exception.

The smoothest path towards mitigating this is by leveraging the
`by lazy` feature of Kotlin, where we only create and interact with
a complex object when actually requested by test method code.  This
strategy gives Ravenwood enough room to successfully instantiate
test classes to decide if it should be executed or ignored via
future annotations.

This change is a purely mechanical adding of `by lazy` in all
relevant locations, as uncovered via local investigation.

Bug: 319647875
Test: atest SystemUiRoboTests
Change-Id: I16b62d790511a9b9f37491f2e0d0f4719783d2ac
parent aea2a174
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -55,7 +55,9 @@ class PrimaryBouncerInteractorWithCoroutinesTest : SysuiTestCase() {
    @Mock private lateinit var keyguardUpdateMonitor: KeyguardUpdateMonitor
    @Mock private lateinit var mSelectedUserInteractor: SelectedUserInteractor
    @Mock private lateinit var faceAuthInteractor: DeviceEntryFaceAuthInteractor
    private val mainHandler = FakeHandler(Looper.getMainLooper())
    private val mainHandler by lazy {
        FakeHandler(Looper.getMainLooper())
    }
    private lateinit var underTest: PrimaryBouncerInteractor

    @Before
+3 −1
Original line number Diff line number Diff line
@@ -66,7 +66,9 @@ class KeyguardBouncerViewModelTest : SysuiTestCase() {
    @Mock private lateinit var faceAuthInteractor: DeviceEntryFaceAuthInteractor

    lateinit var bouncerInteractor: PrimaryBouncerInteractor
    private val mainHandler = FakeHandler(Looper.getMainLooper())
    private val mainHandler by lazy {
        FakeHandler(Looper.getMainLooper())
    }
    val repository = FakeKeyguardBouncerRepository()

    lateinit var underTest: KeyguardBouncerViewModel
+2 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
    @Rule
    public final LeakCheckedTest.SysuiLeakCheck mLeakCheck = new LeakCheckedTest.SysuiLeakCheck();

    WindowManager.LayoutParams mWindowParams = new WindowManager.LayoutParams();
    WindowManager.LayoutParams mWindowParams;

    @Mock
    IDreamOverlayCallback mDreamOverlayCallback;
@@ -184,6 +184,7 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
        when(mDreamOverlayContainerViewController.getContainerView())
                .thenReturn(mDreamOverlayContainerView);

        mWindowParams = new WindowManager.LayoutParams();
        mService = new DreamOverlayService(
                mContext,
                mLifecycleOwner,
+5 −2
Original line number Diff line number Diff line
@@ -56,13 +56,15 @@ class KeyguardInteractorTest : SysuiTestCase() {
    private val testScope = kosmos.testScope
    private val repository = kosmos.fakeKeyguardRepository
    private val sceneInteractor = kosmos.sceneInteractor
    private val commandQueue = FakeCommandQueue()
    private val commandQueue by lazy {
        FakeCommandQueue()
    }
    private val bouncerRepository = FakeKeyguardBouncerRepository()
    private val shadeRepository = FakeShadeRepository()
    private val transitionState: MutableStateFlow<ObservableTransitionState> =
        MutableStateFlow(ObservableTransitionState.Idle(SceneKey.Gone))

    private val underTest =
    private val underTest by lazy {
        KeyguardInteractor(
            repository = repository,
            commandQueue = commandQueue,
@@ -73,6 +75,7 @@ class KeyguardInteractorTest : SysuiTestCase() {
            shadeRepository = shadeRepository,
            sceneInteractorProvider = { sceneInteractor },
        )
    }

    @Before
    fun setUp() {
+6 −3
Original line number Diff line number Diff line
@@ -38,12 +38,12 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.mockito.Mockito.anyBoolean
import org.mockito.Mockito.never
import org.mockito.Mockito.reset
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import org.mockito.Spy

@SmallTest
@OptIn(ExperimentalCoroutinesApi::class)
@@ -51,16 +51,19 @@ import org.mockito.Spy
class LightRevealScrimInteractorTest : SysuiTestCase() {
    private val fakeKeyguardTransitionRepository = FakeKeyguardTransitionRepository()

    @Spy private val fakeLightRevealScrimRepository = FakeLightRevealScrimRepository()
    private val fakeLightRevealScrimRepository by lazy {
        Mockito.spy(FakeLightRevealScrimRepository())
    }

    private val testScope = TestScope()

    private val keyguardTransitionInteractor =
    private val keyguardTransitionInteractor by lazy {
        KeyguardTransitionInteractorFactory.create(
                scope = testScope.backgroundScope,
                repository = fakeKeyguardTransitionRepository,
            )
            .keyguardTransitionInteractor
    }

    private lateinit var underTest: LightRevealScrimInteractor

Loading