Updating unit tests

This commit is contained in:
Maxime NATUREL 2022-10-03 16:02:56 +02:00
parent c0e9d5124c
commit 34e37ea608
3 changed files with 53 additions and 83 deletions

View file

@ -16,7 +16,7 @@
package im.vector.app.core.session.clientinfo
import im.vector.app.test.fakes.FakeActiveSessionHolder
import im.vector.app.test.fakes.FakeSession
import org.amshove.kluent.shouldBe
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
@ -28,11 +28,9 @@ private const val A_CLIENT_URL = "client-url"
class GetMatrixClientInfoUseCaseTest {
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
private val fakeSession = FakeSession()
private val getMatrixClientInfoUseCase = GetMatrixClientInfoUseCase(
activeSessionHolder = fakeActiveSessionHolder.instance
)
private val getMatrixClientInfoUseCase = GetMatrixClientInfoUseCase()
@Test
fun `given a device id and existing content when getting the info then result should contain that info`() {
@ -45,24 +43,12 @@ class GetMatrixClientInfoUseCaseTest {
)
// When
val result = getMatrixClientInfoUseCase.execute(A_DEVICE_ID)
val result = getMatrixClientInfoUseCase.execute(fakeSession, A_DEVICE_ID)
// Then
result shouldBeEqualTo expectedClientInfo
}
@Test
fun `given no active session when getting the info then result should be null`() {
// Given
fakeActiveSessionHolder.givenGetSafeActiveSessionReturns(null)
// When
val result = getMatrixClientInfoUseCase.execute(A_DEVICE_ID)
// Then
result shouldBe null
}
private fun givenClientInfoContent(deviceId: String) {
val type = MATRIX_CLIENT_INFO_KEY_PREFIX + deviceId
val content = mapOf(
@ -70,7 +56,7 @@ class GetMatrixClientInfoUseCaseTest {
Pair("version", A_CLIENT_VERSION),
Pair("url", A_CLIENT_URL),
)
fakeActiveSessionHolder.fakeSession
fakeSession
.fakeSessionAccountDataService
.givenGetUserAccountDataEventReturns(type, content)
}

View file

@ -16,7 +16,7 @@
package im.vector.app.core.session.clientinfo
import im.vector.app.test.fakes.FakeActiveSessionHolder
import im.vector.app.test.fakes.FakeSession
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBe
import org.amshove.kluent.shouldBeEqualTo
@ -28,11 +28,9 @@ private const val A_DEVICE_ID = "device-id"
class SetMatrixClientInfoUseCaseTest {
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
private val fakeSession = FakeSession()
private val setMatrixClientInfoUseCase = SetMatrixClientInfoUseCase(
activeSessionHolder = fakeActiveSessionHolder.instance
)
private val setMatrixClientInfoUseCase = SetMatrixClientInfoUseCase()
@Test
fun `given client info and no error when setting the info then account data is correctly updated`() = runTest {
@ -40,18 +38,18 @@ class SetMatrixClientInfoUseCaseTest {
val type = MATRIX_CLIENT_INFO_KEY_PREFIX + A_DEVICE_ID
val clientInfo = givenClientInfo()
val content = clientInfo.toContent()
fakeActiveSessionHolder.fakeSession
fakeSession
.givenSessionId(A_DEVICE_ID)
fakeActiveSessionHolder.fakeSession
fakeSession
.fakeSessionAccountDataService
.givenUpdateUserAccountDataEventSucceeds()
// When
val result = setMatrixClientInfoUseCase.execute(clientInfo)
val result = setMatrixClientInfoUseCase.execute(fakeSession, clientInfo)
// Then
result.isSuccess shouldBe true
fakeActiveSessionHolder.fakeSession
fakeSession
.fakeSessionAccountDataService
.verifyUpdateUserAccountDataEventSucceeds(type, content)
}
@ -62,20 +60,20 @@ class SetMatrixClientInfoUseCaseTest {
val type = MATRIX_CLIENT_INFO_KEY_PREFIX + A_DEVICE_ID
val clientInfo = givenClientInfo()
val content = clientInfo.toContent()
fakeActiveSessionHolder.fakeSession
fakeSession
.givenSessionId(A_DEVICE_ID)
val error = Exception()
fakeActiveSessionHolder.fakeSession
fakeSession
.fakeSessionAccountDataService
.givenUpdateUserAccountDataEventFailsWithError(error)
// When
val result = setMatrixClientInfoUseCase.execute(clientInfo)
val result = setMatrixClientInfoUseCase.execute(fakeSession, clientInfo)
// Then
result.isFailure shouldBe true
result.exceptionOrNull() shouldBeEqualTo error
fakeActiveSessionHolder.fakeSession
fakeSession
.fakeSessionAccountDataService
.verifyUpdateUserAccountDataEventSucceeds(type, content)
}
@ -86,16 +84,16 @@ class SetMatrixClientInfoUseCaseTest {
val type = MATRIX_CLIENT_INFO_KEY_PREFIX + A_DEVICE_ID
val clientInfo = givenClientInfo()
val content = clientInfo.toContent()
fakeActiveSessionHolder.fakeSession
fakeSession
.givenSessionId(null)
// When
val result = setMatrixClientInfoUseCase.execute(clientInfo)
val result = setMatrixClientInfoUseCase.execute(fakeSession, clientInfo)
// Then
result.isFailure shouldBe true
result.exceptionOrNull()