mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-17 19:58:57 +03:00
Mutualizing mock of asFlow extension
This commit is contained in:
parent
4c3f6db55c
commit
5b3711b634
3 changed files with 45 additions and 15 deletions
|
@ -16,13 +16,11 @@
|
|||
|
||||
package im.vector.app.features.location.live
|
||||
|
||||
import androidx.lifecycle.asFlow
|
||||
import im.vector.app.test.fakes.FakeFlowLiveDataConversions
|
||||
import im.vector.app.test.fakes.FakeSession
|
||||
import io.mockk.every
|
||||
import io.mockk.mockkStatic
|
||||
import im.vector.app.test.fakes.givenAsFlowReturns
|
||||
import io.mockk.unmockkAll
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.junit.After
|
||||
|
@ -38,6 +36,7 @@ private const val AN_EVENT_ID = "event_id"
|
|||
class GetLiveLocationShareSummaryUseCaseTest {
|
||||
|
||||
private val fakeSession = FakeSession()
|
||||
private val fakeFlowLiveDataConversions = FakeFlowLiveDataConversions()
|
||||
|
||||
private val getLiveLocationShareSummaryUseCase = GetLiveLocationShareSummaryUseCase(
|
||||
session = fakeSession
|
||||
|
@ -45,7 +44,7 @@ class GetLiveLocationShareSummaryUseCaseTest {
|
|||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mockkStatic("androidx.lifecycle.FlowLiveDataConversions")
|
||||
fakeFlowLiveDataConversions.setup()
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -61,11 +60,11 @@ class GetLiveLocationShareSummaryUseCaseTest {
|
|||
endOfLiveTimestampMillis = 123,
|
||||
lastLocationDataContent = MessageBeaconLocationDataContent()
|
||||
)
|
||||
val liveData = fakeSession.roomService()
|
||||
fakeSession.roomService()
|
||||
.getRoom(A_ROOM_ID)
|
||||
.locationSharingService()
|
||||
.givenLiveLocationShareSummaryReturns(AN_EVENT_ID, summary)
|
||||
every { liveData.asFlow() } returns flowOf(Optional(summary))
|
||||
.givenAsFlowReturns(Optional(summary))
|
||||
|
||||
val result = getLiveLocationShareSummaryUseCase.execute(A_ROOM_ID, AN_EVENT_ID).first()
|
||||
|
||||
|
|
|
@ -16,16 +16,14 @@
|
|||
|
||||
package im.vector.app.features.location.live.map
|
||||
|
||||
import androidx.lifecycle.asFlow
|
||||
import im.vector.app.features.location.LocationData
|
||||
import im.vector.app.test.fakes.FakeFlowLiveDataConversions
|
||||
import im.vector.app.test.fakes.FakeSession
|
||||
import im.vector.app.test.fakes.givenAsFlowReturns
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkAll
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.junit.After
|
||||
|
@ -41,6 +39,7 @@ class GetListOfUserLiveLocationUseCaseTest {
|
|||
|
||||
private val fakeSession = FakeSession()
|
||||
private val viewStateMapper = mockk<UserLiveLocationViewStateMapper>()
|
||||
private val fakeFlowLiveDataConversions = FakeFlowLiveDataConversions()
|
||||
|
||||
private val getListOfUserLiveLocationUseCase = GetListOfUserLiveLocationUseCase(
|
||||
session = fakeSession,
|
||||
|
@ -49,7 +48,7 @@ class GetListOfUserLiveLocationUseCaseTest {
|
|||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mockkStatic("androidx.lifecycle.FlowLiveDataConversions")
|
||||
fakeFlowLiveDataConversions.setup()
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -78,12 +77,11 @@ class GetListOfUserLiveLocationUseCaseTest {
|
|||
lastLocationDataContent = MessageBeaconLocationDataContent()
|
||||
)
|
||||
val summaries = listOf(summary1, summary2, summary3)
|
||||
val liveData = fakeSession.roomService()
|
||||
fakeSession.roomService()
|
||||
.getRoom(A_ROOM_ID)
|
||||
.locationSharingService()
|
||||
.givenRunningLiveLocationShareSummariesReturns(summaries)
|
||||
|
||||
every { liveData.asFlow() } returns flowOf(summaries)
|
||||
.givenAsFlowReturns(summaries)
|
||||
|
||||
val viewState1 = UserLiveLocationViewState(
|
||||
matrixItem = MatrixItem.UserItem(id = "@userId1:matrix.org", displayName = "User 1", avatarUrl = ""),
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* 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 im.vector.app.test.fakes
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.asFlow
|
||||
import io.mockk.every
|
||||
import io.mockk.mockkStatic
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
|
||||
class FakeFlowLiveDataConversions {
|
||||
fun setup() {
|
||||
mockkStatic("androidx.lifecycle.FlowLiveDataConversions")
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> LiveData<T>.givenAsFlowReturns(value: T) {
|
||||
every { asFlow() } returns flowOf(value)
|
||||
}
|
Loading…
Add table
Reference in a new issue