From 1bc894712efaef4933d3df8ba8ad15fc91217ac0 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Fri, 30 Sep 2022 15:49:04 +0200 Subject: [PATCH] Add unit tests for use cases --- .../usecase/PauseVoiceBroadcastUseCaseTest.kt | 129 ++++++++++++++++++ .../ResumeVoiceBroadcastUseCaseTest.kt | 129 ++++++++++++++++++ .../usecase/StartVoiceBroadcastUseCaseTest.kt | 117 ++++++++++++++++ .../usecase/StopVoiceBroadcastUseCaseTest.kt | 129 ++++++++++++++++++ .../java/im/vector/app/test/fakes/FakeRoom.kt | 3 + .../vector/app/test/fakes/FakeStateService.kt | 29 ++++ 6 files changed, 536 insertions(+) create mode 100644 vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/PauseVoiceBroadcastUseCaseTest.kt create mode 100644 vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/ResumeVoiceBroadcastUseCaseTest.kt create mode 100644 vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCaseTest.kt create mode 100644 vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StopVoiceBroadcastUseCaseTest.kt create mode 100644 vector/src/test/java/im/vector/app/test/fakes/FakeStateService.kt diff --git a/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/PauseVoiceBroadcastUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/PauseVoiceBroadcastUseCaseTest.kt new file mode 100644 index 0000000000..3139f20cd4 --- /dev/null +++ b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/PauseVoiceBroadcastUseCaseTest.kt @@ -0,0 +1,129 @@ +/* + * 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.features.voicebroadcast.usecase + +import im.vector.app.features.voicebroadcast.STATE_ROOM_VOICE_BROADCAST_INFO +import im.vector.app.features.voicebroadcast.model.MessageVoiceBroadcastInfoContent +import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState +import im.vector.app.test.fakes.FakeRoom +import im.vector.app.test.fakes.FakeRoomService +import im.vector.app.test.fakes.FakeSession +import io.mockk.clearAllMocks +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.slot +import kotlinx.coroutines.test.runTest +import org.amshove.kluent.shouldBe +import org.junit.Test +import org.matrix.android.sdk.api.session.events.model.Content +import org.matrix.android.sdk.api.session.events.model.Event +import org.matrix.android.sdk.api.session.events.model.RelationType +import org.matrix.android.sdk.api.session.events.model.toContent +import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent + +private const val A_ROOM_ID = "room_id" +private const val AN_EVENT_ID = "event_id" +private const val A_STARTED_VOICE_BROADCAST_EVENT_ID = "a_started_voice_broadcast_event_id" + +class PauseVoiceBroadcastUseCaseTest { + + private val fakeRoom = FakeRoom() + private val fakeSession = FakeSession(fakeRoomService = FakeRoomService(fakeRoom)) + private val pauseVoiceBroadcastUseCase = PauseVoiceBroadcastUseCase(fakeSession) + + @Test + fun `given a room id with a potential existing voice broadcast state when calling execute then the voice broadcast is paused or not`() = runTest { + val cases = listOf(null).plus(VoiceBroadcastState.values()).map { + when (it) { + VoiceBroadcastState.STARTED, + VoiceBroadcastState.RESUMED -> Case(it, true) + VoiceBroadcastState.STOPPED, + VoiceBroadcastState.PAUSED, + null -> Case(it, false) + } + } + + cases.forEach { case -> + if (case.canPauseVoiceBroadcast) { + testVoiceBroadcastPaused(case.previousState) + } else { + testVoiceBroadcastNotPaused(case.previousState) + } + } + } + + private suspend fun testVoiceBroadcastPaused(previousState: VoiceBroadcastState?) { + // Given + clearAllMocks() + givenAVoiceBroadcastState(previousState) + val voiceBroadcastInfoContentInterceptor = slot() + coEvery { fakeRoom.stateService().sendStateEvent(any(), any(), capture(voiceBroadcastInfoContentInterceptor)) } coAnswers { AN_EVENT_ID } + + // When + pauseVoiceBroadcastUseCase.execute(A_ROOM_ID) + + // Then + coVerify { + fakeRoom.stateService().sendStateEvent( + eventType = STATE_ROOM_VOICE_BROADCAST_INFO, + stateKey = fakeSession.myUserId, + body = any(), + ) + } + val voiceBroadcastInfoContent = voiceBroadcastInfoContentInterceptor.captured.toModel() + voiceBroadcastInfoContent?.voiceBroadcastState shouldBe VoiceBroadcastState.PAUSED + voiceBroadcastInfoContent?.relatesTo?.type shouldBe RelationType.REFERENCE + voiceBroadcastInfoContent?.relatesTo?.eventId shouldBe A_STARTED_VOICE_BROADCAST_EVENT_ID + } + + private suspend fun testVoiceBroadcastNotPaused(previousState: VoiceBroadcastState?) { + // Given + clearAllMocks() + givenAVoiceBroadcastState(previousState) + + // When + pauseVoiceBroadcastUseCase.execute(A_ROOM_ID) + + // Then + coVerify(exactly = 0) { fakeRoom.stateService().sendStateEvent(any(), any(), any()) } + } + + private fun givenAVoiceBroadcastState(state: VoiceBroadcastState?) { + val relatesTo = when (state) { + VoiceBroadcastState.STARTED, + null -> null + VoiceBroadcastState.PAUSED, + VoiceBroadcastState.RESUMED, + VoiceBroadcastState.STOPPED -> RelationDefaultContent(RelationType.REFERENCE, A_STARTED_VOICE_BROADCAST_EVENT_ID) + } + val event = state?.let { + Event( + eventId = if (state == VoiceBroadcastState.STARTED) A_STARTED_VOICE_BROADCAST_EVENT_ID else AN_EVENT_ID, + type = STATE_ROOM_VOICE_BROADCAST_INFO, + stateKey = fakeSession.myUserId, + content = MessageVoiceBroadcastInfoContent( + voiceBroadcastStateStr = state.value, + relatesTo = relatesTo + ).toContent() + ) + } + fakeRoom.stateService().givenGetStateEvent(event) + } + + private data class Case(val previousState: VoiceBroadcastState?, val canPauseVoiceBroadcast: Boolean) +} diff --git a/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/ResumeVoiceBroadcastUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/ResumeVoiceBroadcastUseCaseTest.kt new file mode 100644 index 0000000000..23d506482b --- /dev/null +++ b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/ResumeVoiceBroadcastUseCaseTest.kt @@ -0,0 +1,129 @@ +/* + * 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.features.voicebroadcast.usecase + +import im.vector.app.features.voicebroadcast.STATE_ROOM_VOICE_BROADCAST_INFO +import im.vector.app.features.voicebroadcast.model.MessageVoiceBroadcastInfoContent +import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState +import im.vector.app.test.fakes.FakeRoom +import im.vector.app.test.fakes.FakeRoomService +import im.vector.app.test.fakes.FakeSession +import io.mockk.clearAllMocks +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.slot +import kotlinx.coroutines.test.runTest +import org.amshove.kluent.shouldBe +import org.junit.Test +import org.matrix.android.sdk.api.session.events.model.Content +import org.matrix.android.sdk.api.session.events.model.Event +import org.matrix.android.sdk.api.session.events.model.RelationType +import org.matrix.android.sdk.api.session.events.model.toContent +import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent + +private const val A_ROOM_ID = "room_id" +private const val AN_EVENT_ID = "event_id" +private const val A_STARTED_VOICE_BROADCAST_EVENT_ID = "a_started_voice_broadcast_event_id" + +class ResumeVoiceBroadcastUseCaseTest { + + private val fakeRoom = FakeRoom() + private val fakeSession = FakeSession(fakeRoomService = FakeRoomService(fakeRoom)) + private val resumeVoiceBroadcastUseCase = ResumeVoiceBroadcastUseCase(fakeSession) + + @Test + fun `given a room id with a potential existing voice broadcast state when calling execute then the voice broadcast is resumed or not`() = runTest { + val cases = listOf(null).plus(VoiceBroadcastState.values()).map { + when (it) { + VoiceBroadcastState.PAUSED -> Case(it, true) + VoiceBroadcastState.STARTED, + VoiceBroadcastState.RESUMED, + VoiceBroadcastState.STOPPED, + null -> Case(it, false) + } + } + + cases.forEach { case -> + if (case.canResumeVoiceBroadcast) { + testVoiceBroadcastResumed(case.previousState) + } else { + testVoiceBroadcastNotResumed(case.previousState) + } + } + } + + private suspend fun testVoiceBroadcastResumed(previousState: VoiceBroadcastState?) { + // Given + clearAllMocks() + givenAVoiceBroadcastState(previousState) + val voiceBroadcastInfoContentInterceptor = slot() + coEvery { fakeRoom.stateService().sendStateEvent(any(), any(), capture(voiceBroadcastInfoContentInterceptor)) } coAnswers { AN_EVENT_ID } + + // When + resumeVoiceBroadcastUseCase.execute(A_ROOM_ID) + + // Then + coVerify { + fakeRoom.stateService().sendStateEvent( + eventType = STATE_ROOM_VOICE_BROADCAST_INFO, + stateKey = fakeSession.myUserId, + body = any(), + ) + } + val voiceBroadcastInfoContent = voiceBroadcastInfoContentInterceptor.captured.toModel() + voiceBroadcastInfoContent?.voiceBroadcastState shouldBe VoiceBroadcastState.RESUMED + voiceBroadcastInfoContent?.relatesTo?.type shouldBe RelationType.REFERENCE + voiceBroadcastInfoContent?.relatesTo?.eventId shouldBe A_STARTED_VOICE_BROADCAST_EVENT_ID + } + + private suspend fun testVoiceBroadcastNotResumed(previousState: VoiceBroadcastState?) { + // Given + clearAllMocks() + givenAVoiceBroadcastState(previousState) + + // When + resumeVoiceBroadcastUseCase.execute(A_ROOM_ID) + + // Then + coVerify(exactly = 0) { fakeRoom.stateService().sendStateEvent(any(), any(), any()) } + } + + private fun givenAVoiceBroadcastState(state: VoiceBroadcastState?) { + val relatesTo = when (state) { + VoiceBroadcastState.STARTED, + null -> null + VoiceBroadcastState.PAUSED, + VoiceBroadcastState.RESUMED, + VoiceBroadcastState.STOPPED -> RelationDefaultContent(RelationType.REFERENCE, A_STARTED_VOICE_BROADCAST_EVENT_ID) + } + val event = state?.let { + Event( + eventId = if (state == VoiceBroadcastState.STARTED) A_STARTED_VOICE_BROADCAST_EVENT_ID else AN_EVENT_ID, + type = STATE_ROOM_VOICE_BROADCAST_INFO, + stateKey = fakeSession.myUserId, + content = MessageVoiceBroadcastInfoContent( + voiceBroadcastStateStr = state.value, + relatesTo = relatesTo + ).toContent() + ) + } + fakeRoom.stateService().givenGetStateEvent(event) + } + + private data class Case(val previousState: VoiceBroadcastState?, val canResumeVoiceBroadcast: Boolean) +} diff --git a/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCaseTest.kt new file mode 100644 index 0000000000..3bb04f3a7a --- /dev/null +++ b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StartVoiceBroadcastUseCaseTest.kt @@ -0,0 +1,117 @@ +/* + * 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.features.voicebroadcast.usecase + +import im.vector.app.features.voicebroadcast.STATE_ROOM_VOICE_BROADCAST_INFO +import im.vector.app.features.voicebroadcast.model.MessageVoiceBroadcastInfoContent +import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState +import im.vector.app.test.fakes.FakeRoom +import im.vector.app.test.fakes.FakeRoomService +import im.vector.app.test.fakes.FakeSession +import io.mockk.clearAllMocks +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.slot +import kotlinx.coroutines.test.runTest +import org.amshove.kluent.shouldBe +import org.amshove.kluent.shouldBeNull +import org.junit.Test +import org.matrix.android.sdk.api.session.events.model.Content +import org.matrix.android.sdk.api.session.events.model.Event +import org.matrix.android.sdk.api.session.events.model.toContent +import org.matrix.android.sdk.api.session.events.model.toModel + +private const val A_ROOM_ID = "room_id" +private const val AN_EVENT_ID = "event_id" + +class StartVoiceBroadcastUseCaseTest { + + private val fakeRoom = FakeRoom() + private val fakeSession = FakeSession(fakeRoomService = FakeRoomService(fakeRoom)) + private val startVoiceBroadcastUseCase = StartVoiceBroadcastUseCase(fakeSession) + + @Test + fun `given a room id with a potential existing voice broadcast state when calling execute then the voice broadcast is started or not`() = runTest { + val cases = listOf(null).plus(VoiceBroadcastState.values()).map { + when (it) { + VoiceBroadcastState.STARTED, + VoiceBroadcastState.PAUSED, + VoiceBroadcastState.RESUMED -> Case(it, false) + VoiceBroadcastState.STOPPED, + null -> Case(it, true) + } + } + + cases.forEach { case -> + if (case.canStartVoiceBroadcast) { + testVoiceBroadcastStarted(case.previousState) + } else { + testVoiceBroadcastNotStarted(case.previousState) + } + } + } + + private suspend fun testVoiceBroadcastStarted(previousState: VoiceBroadcastState?) { + // Given + clearAllMocks() + givenAVoiceBroadcastState(previousState) + val voiceBroadcastInfoContentInterceptor = slot() + coEvery { fakeRoom.stateService().sendStateEvent(any(), any(), capture(voiceBroadcastInfoContentInterceptor)) } coAnswers { AN_EVENT_ID } + + // When + startVoiceBroadcastUseCase.execute(A_ROOM_ID) + + // Then + coVerify { + fakeRoom.stateService().sendStateEvent( + eventType = STATE_ROOM_VOICE_BROADCAST_INFO, + stateKey = fakeSession.myUserId, + body = any(), + ) + } + val voiceBroadcastInfoContent = voiceBroadcastInfoContentInterceptor.captured.toModel() + voiceBroadcastInfoContent?.voiceBroadcastState shouldBe VoiceBroadcastState.STARTED + voiceBroadcastInfoContent?.relatesTo.shouldBeNull() + } + + private suspend fun testVoiceBroadcastNotStarted(previousState: VoiceBroadcastState?) { + // Given + clearAllMocks() + givenAVoiceBroadcastState(previousState) + + // When + startVoiceBroadcastUseCase.execute(A_ROOM_ID) + + // Then + coVerify(exactly = 0) { fakeRoom.stateService().sendStateEvent(any(), any(), any()) } + } + + private fun givenAVoiceBroadcastState(state: VoiceBroadcastState?) { + val event = state?.let { + Event( + type = STATE_ROOM_VOICE_BROADCAST_INFO, + stateKey = fakeSession.myUserId, + content = MessageVoiceBroadcastInfoContent( + voiceBroadcastStateStr = state.value + ).toContent() + ) + } + fakeRoom.stateService().givenGetStateEvent(event) + } + + private data class Case(val previousState: VoiceBroadcastState?, val canStartVoiceBroadcast: Boolean) +} diff --git a/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StopVoiceBroadcastUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StopVoiceBroadcastUseCaseTest.kt new file mode 100644 index 0000000000..aa8dcddf30 --- /dev/null +++ b/vector/src/test/java/im/vector/app/features/voicebroadcast/usecase/StopVoiceBroadcastUseCaseTest.kt @@ -0,0 +1,129 @@ +/* + * 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.features.voicebroadcast.usecase + +import im.vector.app.features.voicebroadcast.STATE_ROOM_VOICE_BROADCAST_INFO +import im.vector.app.features.voicebroadcast.model.MessageVoiceBroadcastInfoContent +import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState +import im.vector.app.test.fakes.FakeRoom +import im.vector.app.test.fakes.FakeRoomService +import im.vector.app.test.fakes.FakeSession +import io.mockk.clearAllMocks +import io.mockk.coEvery +import io.mockk.coVerify +import io.mockk.slot +import kotlinx.coroutines.test.runTest +import org.amshove.kluent.shouldBe +import org.junit.Test +import org.matrix.android.sdk.api.session.events.model.Content +import org.matrix.android.sdk.api.session.events.model.Event +import org.matrix.android.sdk.api.session.events.model.RelationType +import org.matrix.android.sdk.api.session.events.model.toContent +import org.matrix.android.sdk.api.session.events.model.toModel +import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent + +private const val A_ROOM_ID = "room_id" +private const val AN_EVENT_ID = "event_id" +private const val A_STARTED_VOICE_BROADCAST_EVENT_ID = "a_started_voice_broadcast_event_id" + +class StopVoiceBroadcastUseCaseTest { + + private val fakeRoom = FakeRoom() + private val fakeSession = FakeSession(fakeRoomService = FakeRoomService(fakeRoom)) + private val stopVoiceBroadcastUseCase = StopVoiceBroadcastUseCase(fakeSession) + + @Test + fun `given a room id with a potential existing voice broadcast state when calling execute then the voice broadcast is stopped or not`() = runTest { + val cases = listOf(null).plus(VoiceBroadcastState.values()).map { + when (it) { + VoiceBroadcastState.STARTED, + VoiceBroadcastState.RESUMED, + VoiceBroadcastState.PAUSED -> Case(it, true) + VoiceBroadcastState.STOPPED, + null -> Case(it, false) + } + } + + cases.forEach { case -> + if (case.canStopVoiceBroadcast) { + testVoiceBroadcastStopped(case.previousState) + } else { + testVoiceBroadcastNotStopped(case.previousState) + } + } + } + + private suspend fun testVoiceBroadcastStopped(previousState: VoiceBroadcastState?) { + // Given + clearAllMocks() + givenAVoiceBroadcastState(previousState) + val voiceBroadcastInfoContentInterceptor = slot() + coEvery { fakeRoom.stateService().sendStateEvent(any(), any(), capture(voiceBroadcastInfoContentInterceptor)) } coAnswers { AN_EVENT_ID } + + // When + stopVoiceBroadcastUseCase.execute(A_ROOM_ID) + + // Then + coVerify { + fakeRoom.stateService().sendStateEvent( + eventType = STATE_ROOM_VOICE_BROADCAST_INFO, + stateKey = fakeSession.myUserId, + body = any(), + ) + } + val voiceBroadcastInfoContent = voiceBroadcastInfoContentInterceptor.captured.toModel() + voiceBroadcastInfoContent?.voiceBroadcastState shouldBe VoiceBroadcastState.STOPPED + voiceBroadcastInfoContent?.relatesTo?.type shouldBe RelationType.REFERENCE + voiceBroadcastInfoContent?.relatesTo?.eventId shouldBe A_STARTED_VOICE_BROADCAST_EVENT_ID + } + + private suspend fun testVoiceBroadcastNotStopped(previousState: VoiceBroadcastState?) { + // Given + clearAllMocks() + givenAVoiceBroadcastState(previousState) + + // When + stopVoiceBroadcastUseCase.execute(A_ROOM_ID) + + // Then + coVerify(exactly = 0) { fakeRoom.stateService().sendStateEvent(any(), any(), any()) } + } + + private fun givenAVoiceBroadcastState(state: VoiceBroadcastState?) { + val relatesTo = when (state) { + VoiceBroadcastState.STARTED, + null -> null + VoiceBroadcastState.PAUSED, + VoiceBroadcastState.RESUMED, + VoiceBroadcastState.STOPPED -> RelationDefaultContent(RelationType.REFERENCE, A_STARTED_VOICE_BROADCAST_EVENT_ID) + } + val event = state?.let { + Event( + eventId = if (state == VoiceBroadcastState.STARTED) A_STARTED_VOICE_BROADCAST_EVENT_ID else AN_EVENT_ID, + type = STATE_ROOM_VOICE_BROADCAST_INFO, + stateKey = fakeSession.myUserId, + content = MessageVoiceBroadcastInfoContent( + voiceBroadcastStateStr = state.value, + relatesTo = relatesTo + ).toContent() + ) + } + fakeRoom.stateService().givenGetStateEvent(event) + } + + private data class Case(val previousState: VoiceBroadcastState?, val canStopVoiceBroadcast: Boolean) +} diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeRoom.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeRoom.kt index 865b01551a..7835c314ef 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeRoom.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeRoom.kt @@ -24,6 +24,7 @@ class FakeRoom( private val fakeSendService: FakeSendService = FakeSendService(), private val fakeTimelineService: FakeTimelineService = FakeTimelineService(), private val fakeRelationService: FakeRelationService = FakeRelationService(), + private val fakeStateService: FakeStateService = FakeStateService(), ) : Room by mockk() { override fun locationSharingService() = fakeLocationSharingService @@ -33,4 +34,6 @@ class FakeRoom( override fun timelineService() = fakeTimelineService override fun relationService() = fakeRelationService + + override fun stateService() = fakeStateService } diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeStateService.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeStateService.kt new file mode 100644 index 0000000000..03a0cf07d8 --- /dev/null +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeStateService.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2021 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 io.mockk.every +import io.mockk.mockk +import org.matrix.android.sdk.api.session.events.model.Event +import org.matrix.android.sdk.api.session.room.state.StateService + +class FakeStateService : StateService by mockk(relaxed = true) { + + fun givenGetStateEvent(event: Event?) { + every { getStateEvent(any(), any()) } returns event + } +}