Adding unit tests for dispose methods

This commit is contained in:
Maxime NATUREL 2023-01-24 15:43:43 +01:00
parent 470218ca52
commit 184a25b811
4 changed files with 58 additions and 5 deletions

View file

@ -25,7 +25,6 @@ class RoomPollRepository @Inject constructor(
private val roomPollDataSource: RoomPollDataSource, private val roomPollDataSource: RoomPollDataSource,
) { ) {
// TODO add unit tests
fun dispose(roomId: String) { fun dispose(roomId: String) {
roomPollDataSource.dispose(roomId) roomPollDataSource.dispose(roomId)
} }

View file

@ -17,16 +17,12 @@
package im.vector.app.features.roomprofile.polls.list.domain package im.vector.app.features.roomprofile.polls.list.domain
import im.vector.app.features.roomprofile.polls.list.data.RoomPollRepository import im.vector.app.features.roomprofile.polls.list.data.RoomPollRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import javax.inject.Inject import javax.inject.Inject
class DisposePollHistoryUseCase @Inject constructor( class DisposePollHistoryUseCase @Inject constructor(
private val roomPollRepository: RoomPollRepository, private val roomPollRepository: RoomPollRepository,
) { ) {
// TODO add unit tests
fun execute(roomId: String) { fun execute(roomId: String) {
roomPollRepository.dispose(roomId) roomPollRepository.dispose(roomId)
} }

View file

@ -20,6 +20,7 @@ import io.mockk.coEvery
import io.mockk.coJustRun import io.mockk.coJustRun
import io.mockk.coVerify import io.mockk.coVerify
import io.mockk.every import io.mockk.every
import io.mockk.justRun
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.firstOrNull
@ -40,6 +41,18 @@ class RoomPollRepositoryTest {
roomPollDataSource = fakeRoomPollDataSource, roomPollDataSource = fakeRoomPollDataSource,
) )
@Test
fun `given data source when dispose then correct method of data source is called`() {
// Given
justRun { fakeRoomPollDataSource.dispose(A_ROOM_ID) }
// When
roomPollRepository.dispose(A_ROOM_ID)
// Then
verify { fakeRoomPollDataSource.dispose(A_ROOM_ID) }
}
@Test @Test
fun `given data source when getting polls then correct method of data source is called`() = runTest { fun `given data source when getting polls then correct method of data source is called`() = runTest {
// Given // Given

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2023 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.roomprofile.polls.list.domain
import im.vector.app.features.roomprofile.polls.list.data.RoomPollRepository
import io.mockk.coVerify
import io.mockk.justRun
import io.mockk.mockk
import org.junit.Test
internal class DisposePollHistoryUseCaseTest {
private val fakeRoomPollRepository = mockk<RoomPollRepository>()
private val disposePollHistoryUseCase = DisposePollHistoryUseCase(
roomPollRepository = fakeRoomPollRepository,
)
@Test
fun `given repo when execute then correct method of repo is called`() {
// Given
val aRoomId = "roomId"
justRun { fakeRoomPollRepository.dispose(aRoomId) }
// When
disposePollHistoryUseCase.execute(aRoomId)
// Then
coVerify { fakeRoomPollRepository.dispose(aRoomId) }
}
}