summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractorTest.kt21
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/display/data/repository/FakeDisplayRepository.kt42
2 files changed, 44 insertions, 19 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractorTest.kt
index 1b597f44d23e..eb0ad698e34b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractorTest.kt
@@ -25,14 +25,11 @@ import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.FlowValue
import com.android.systemui.coroutines.collectLastValue
-import com.android.systemui.display.data.repository.DisplayRepository
+import com.android.systemui.display.data.repository.FakeDisplayRepository
+import com.android.systemui.display.data.repository.display
import com.android.systemui.display.domain.interactor.ConnectedDisplayInteractor.State
-import com.android.systemui.util.mockito.mock
-import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
@@ -131,18 +128,4 @@ class ConnectedDisplayInteractorTest : SysuiTestCase() {
private fun TestScope.lastValue(): FlowValue<State?> =
collectLastValue(connectedDisplayStateProvider.connectedDisplayState)
-
- private fun display(type: Int, flags: Int = 0): Display {
- return mock<Display>().also { mockDisplay ->
- whenever(mockDisplay.type).thenReturn(type)
- whenever(mockDisplay.flags).thenReturn(flags)
- }
- }
-
- private class FakeDisplayRepository : DisplayRepository {
- private val flow = MutableSharedFlow<Set<Display>>()
- suspend fun emit(value: Set<Display>) = flow.emit(value)
- override val displays: Flow<Set<Display>>
- get() = flow
- }
}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/display/data/repository/FakeDisplayRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/display/data/repository/FakeDisplayRepository.kt
new file mode 100644
index 000000000000..715d66191428
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/display/data/repository/FakeDisplayRepository.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.systemui.display.data.repository
+
+import android.view.Display
+import com.android.systemui.util.mockito.mock
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableSharedFlow
+import org.mockito.Mockito.`when` as whenever
+
+/** Creates a mock display. */
+fun display(type: Int, flags: Int = 0, id: Int = 0): Display {
+ return mock {
+ whenever(this.displayId).thenReturn(id)
+ whenever(this.type).thenReturn(type)
+ whenever(this.flags).thenReturn(flags)
+ }
+}
+
+/** Fake [DisplayRepository] implementation for testing. */
+class FakeDisplayRepository : DisplayRepository {
+ private val flow = MutableSharedFlow<Set<Display>>()
+
+ /** Emits [value] as [displays] flow value. */
+ suspend fun emit(value: Set<Display>) = flow.emit(value)
+
+ override val displays: Flow<Set<Display>>
+ get() = flow
+}