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

Commit a781cde8 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Defer (more) complex object creation until used.

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.

This change is a continuation of the recent `by lazy` work, expanded
to catch examples that have emerged over the recent few weeks.  There
are also a few tests where `by lazy` left some dirty state between
test cases, so we pivot those tests to use `lateinit` instead so
that all existing tests remain passing.

Bug: 319647875
Test: atest SystemUiRoboTests
Change-Id: I2a646ad8d189fd9545123e9585796f35b4290b12
parent 4bdcf7e9
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -41,10 +41,10 @@ import org.junit.runner.RunWith
class FingerprintPropertyInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val underTest = kosmos.fingerprintPropertyInteractor
    private val repository = kosmos.fingerprintPropertyRepository
    private val configurationRepository = kosmos.fakeConfigurationRepository
    private val displayRepository = kosmos.displayRepository
    private val underTest by lazy { kosmos.fingerprintPropertyInteractor }
    private val repository by lazy { kosmos.fingerprintPropertyRepository }
    private val configurationRepository by lazy { kosmos.fakeConfigurationRepository }
    private val displayRepository by lazy { kosmos.displayRepository }

    @Test
    fun sensorLocation_resolution1f() =
+3 −2
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ class AuthMethodBouncerViewModelTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val bouncerInteractor = kosmos.bouncerInteractor
    private val underTest =
    private val bouncerInteractor by lazy { kosmos.bouncerInteractor }
    private val underTest by lazy {
        PinBouncerViewModel(
            applicationContext = context,
            viewModelScope = testScope.backgroundScope,
@@ -49,6 +49,7 @@ class AuthMethodBouncerViewModelTest : SysuiTestCase() {
            simBouncerInteractor = kosmos.simBouncerInteractor,
            authenticationMethod = AuthenticationMethodModel.Pin,
        )
    }

    @Test
    fun animateFailure() =
+2 −2
Original line number Diff line number Diff line
@@ -58,8 +58,8 @@ class BouncerViewModelTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val authenticationInteractor = kosmos.authenticationInteractor
    private val bouncerInteractor = kosmos.bouncerInteractor
    private val authenticationInteractor by lazy { kosmos.authenticationInteractor }
    private val bouncerInteractor by lazy { kosmos.bouncerInteractor }
    private lateinit var underTest: BouncerViewModel

    @Before
+5 −4
Original line number Diff line number Diff line
@@ -52,17 +52,18 @@ class PasswordBouncerViewModelTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val authenticationInteractor = kosmos.authenticationInteractor
    private val sceneInteractor = kosmos.sceneInteractor
    private val bouncerInteractor = kosmos.bouncerInteractor
    private val bouncerViewModel = kosmos.bouncerViewModel
    private val sceneInteractor by lazy { kosmos.sceneInteractor }
    private val bouncerInteractor by lazy { kosmos.bouncerInteractor }
    private val bouncerViewModel by lazy { kosmos.bouncerViewModel }
    private val isInputEnabled = MutableStateFlow(true)

    private val underTest =
    private val underTest by lazy {
        PasswordBouncerViewModel(
            viewModelScope = testScope.backgroundScope,
            interactor = bouncerInteractor,
            isInputEnabled.asStateFlow(),
        )
    }

    @Before
    fun setUp() {
+6 −5
Original line number Diff line number Diff line
@@ -53,17 +53,18 @@ class PatternBouncerViewModelTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val authenticationInteractor = kosmos.authenticationInteractor
    private val sceneInteractor = kosmos.sceneInteractor
    private val bouncerInteractor = kosmos.bouncerInteractor
    private val bouncerViewModel = kosmos.bouncerViewModel
    private val underTest =
    private val authenticationInteractor by lazy { kosmos.authenticationInteractor }
    private val sceneInteractor by lazy { kosmos.sceneInteractor }
    private val bouncerInteractor by lazy { kosmos.bouncerInteractor }
    private val bouncerViewModel by lazy { kosmos.bouncerViewModel }
    private val underTest by lazy {
        PatternBouncerViewModel(
            applicationContext = context,
            viewModelScope = testScope.backgroundScope,
            interactor = bouncerInteractor,
            isInputEnabled = MutableStateFlow(true).asStateFlow(),
        )
    }

    private val containerSize = 90 // px
    private val dotSize = 30 // px
Loading