mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Adding unit tests for dispose methods
This commit is contained in:
parent
470218ca52
commit
184a25b811
4 changed files with 58 additions and 5 deletions
|
@ -25,7 +25,6 @@ class RoomPollRepository @Inject constructor(
|
|||
private val roomPollDataSource: RoomPollDataSource,
|
||||
) {
|
||||
|
||||
// TODO add unit tests
|
||||
fun dispose(roomId: String) {
|
||||
roomPollDataSource.dispose(roomId)
|
||||
}
|
||||
|
|
|
@ -17,16 +17,12 @@
|
|||
package im.vector.app.features.roomprofile.polls.list.domain
|
||||
|
||||
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
|
||||
|
||||
class DisposePollHistoryUseCase @Inject constructor(
|
||||
private val roomPollRepository: RoomPollRepository,
|
||||
) {
|
||||
|
||||
// TODO add unit tests
|
||||
fun execute(roomId: String) {
|
||||
roomPollRepository.dispose(roomId)
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import io.mockk.coEvery
|
|||
import io.mockk.coJustRun
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
import io.mockk.justRun
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
|
@ -40,6 +41,18 @@ class RoomPollRepositoryTest {
|
|||
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
|
||||
fun `given data source when getting polls then correct method of data source is called`() = runTest {
|
||||
// Given
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue