Loading packages/SystemUI/tests/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractorTest.kt +2 −19 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 } } packages/SystemUI/tests/utils/src/com/android/systemui/display/data/repository/FakeDisplayRepository.kt 0 → 100644 +42 −0 Original line number Diff line number Diff line /* * 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 } Loading
packages/SystemUI/tests/src/com/android/systemui/display/domain/interactor/ConnectedDisplayInteractorTest.kt +2 −19 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 } }
packages/SystemUI/tests/utils/src/com/android/systemui/display/data/repository/FakeDisplayRepository.kt 0 → 100644 +42 −0 Original line number Diff line number Diff line /* * 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 }