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

Commit a3538466 authored by Will Osborn's avatar Will Osborn
Browse files

Update FakePerDisplayRepository with forEach change

Test: locally tested on Tangor
Bug: 399371607
Flag: EXEMPT refactor

Change-Id: I7ee8e90e169ad7ec2707ed6424675d66a5a4474f
parent 5175a303
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.systemui.dump.dumpManager
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.testKosmos
import com.android.systemui.util.containsExactly
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
@@ -147,6 +148,20 @@ class PerDisplayInstanceRepositoryImplTest : SysuiTestCase() {
            assertThat(underTest[NON_DEFAULT_DISPLAY_ID]).isNotNull()
        }

    @Test
    fun perDisplay_forEach_IteratesCorrectly() =
        testScope.runTest {
            val displayIds = mutableSetOf<Int>()
            underTest.forEach(createIfAbsent = false) { instance ->
                displayIds.add(instance.displayId)
            }
            assertThat(displayIds).isEmpty()
            underTest.forEach(createIfAbsent = true) { instance ->
                displayIds.add(instance.displayId)
            }
            assertThat(displayIds).containsExactly(DEFAULT_DISPLAY_ID, NON_DEFAULT_DISPLAY_ID)
        }

    private fun createDisplay(displayId: Int): Display =
        display(type = Display.TYPE_INTERNAL, id = displayId)

+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.display.data.repository

import com.android.app.displaylib.PerDisplayRepository
import java.util.function.Consumer

// TODO b/401305290 - move to displaylib
class FakePerDisplayRepository<T> : PerDisplayRepository<T> {
@@ -37,4 +38,8 @@ class FakePerDisplayRepository<T> : PerDisplayRepository<T> {

    override val debugName: String
        get() = "FakePerDisplayRepository"

    override fun forEach(createIfAbsent: Boolean, action: Consumer<T>) {
        instances.forEach { (_, t) -> action.accept(t) }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.display.data.repository

import com.android.app.displaylib.PerDisplayRepository
import java.util.function.Consumer
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope

@@ -30,4 +31,8 @@ class FakeDisplayScopeRepository(
    override fun get(displayId: Int): CoroutineScope {
        return perDisplayScopes.computeIfAbsent(displayId) { CoroutineScope(dispatcher) }
    }

    override fun forEach(createIfAbsent: Boolean, action: Consumer<CoroutineScope>) {
        perDisplayScopes.forEach { (_, scope) -> action.accept(scope) }
    }
}