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

Commit 653792b0 authored by Will Osborn's avatar Will Osborn Committed by Android (Google) Code Review
Browse files

Merge "Update FakePerDisplayRepository with forEach change" into main

parents 6085f394 a3538466
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) }
    }
}