Adding unit tests for application section visibility use case

This commit is contained in:
Maxime NATUREL 2022-10-06 10:08:54 +02:00
parent 9f9f6e14be
commit 25a3d831f1
4 changed files with 149 additions and 7 deletions

View file

@ -22,7 +22,6 @@ import javax.inject.Inject
class CheckIfSectionApplicationIsVisibleUseCase @Inject constructor() {
// TODO add unit tests
fun execute(matrixClientInfoContent: MatrixClientInfoContent?): Boolean {
return matrixClientInfoContent?.name?.isNotEmpty().orFalse() ||
matrixClientInfoContent?.version?.isNotEmpty().orFalse() ||

View file

@ -0,0 +1,145 @@
/*
* 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.settings.devices.v2.details
import im.vector.app.core.session.clientinfo.MatrixClientInfoContent
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
private const val AN_APP_NAME = "app-name"
private const val AN_APP_VERSION = "app-version"
private const val AN_APP_URL = "app-url"
class CheckIfSectionApplicationIsVisibleUseCaseTest {
private val checkIfSectionApplicationIsVisibleUseCase = CheckIfSectionApplicationIsVisibleUseCase()
@Test
fun `given client info with name, version or url when checking is application section is visible then it returns true`() {
// Given
val clientInfoList = listOf(
givenAClientInfo(
name = AN_APP_NAME,
version = null,
url = null,
),
givenAClientInfo(
name = null,
version = AN_APP_VERSION,
url = null,
),
givenAClientInfo(
name = null,
version = null,
url = AN_APP_URL,
),
givenAClientInfo(
name = AN_APP_NAME,
version = AN_APP_VERSION,
url = null,
),
givenAClientInfo(
name = AN_APP_NAME,
version = null,
url = AN_APP_URL,
),
givenAClientInfo(
name = null,
version = AN_APP_VERSION,
url = AN_APP_URL,
),
givenAClientInfo(
name = AN_APP_NAME,
version = AN_APP_VERSION,
url = AN_APP_URL,
),
)
clientInfoList.forEach { clientInfo ->
// When
val result = checkIfSectionApplicationIsVisibleUseCase.execute(clientInfo)
// Then
result shouldBeEqualTo true
}
}
@Test
fun `given client info with missing application info when checking is application section is visible then it returns false`() {
// Given
val clientInfoList = listOf(
givenAClientInfo(
name = null,
version = null,
url = null,
),
givenAClientInfo(
name = "",
version = null,
url = null,
),
givenAClientInfo(
name = null,
version = "",
url = null,
),
givenAClientInfo(
name = null,
version = null,
url = "",
),
givenAClientInfo(
name = "",
version = "",
url = null,
),
givenAClientInfo(
name = "",
version = null,
url = "",
),
givenAClientInfo(
name = null,
version = "",
url = "",
),
givenAClientInfo(
name = "",
version = "",
url = "",
),
)
clientInfoList.forEach { clientInfo ->
// When
val result = checkIfSectionApplicationIsVisibleUseCase.execute(clientInfo)
// Then
result shouldBeEqualTo false
}
}
private fun givenAClientInfo(
name: String?,
version: String?,
url: String?,
) = MatrixClientInfoContent(
name = name,
version = version,
url = url,
)
}

View file

@ -18,7 +18,6 @@ package im.vector.app.features.settings.devices.v2.details
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
@ -30,7 +29,7 @@ class CheckIfSectionDeviceIsVisibleUseCaseTest {
private val checkIfSectionDeviceIsVisibleUseCase = CheckIfSectionDeviceIsVisibleUseCase()
@Test
fun `given device info with Ip address when checking is device section is visible then it returns true`() = runTest {
fun `given device info with Ip address when checking is device section is visible then it returns true`() {
// Given
val deviceInfo = givenADeviceInfo(AN_IP_ADDRESS)
@ -42,7 +41,7 @@ class CheckIfSectionDeviceIsVisibleUseCaseTest {
}
@Test
fun `given device info with empty or null Ip address when checking is device section is visible then it returns false`() = runTest {
fun `given device info with empty or null Ip address when checking is device section is visible then it returns false`() {
// Given
val deviceInfo1 = givenADeviceInfo("")
val deviceInfo2 = givenADeviceInfo(null)

View file

@ -18,7 +18,6 @@ package im.vector.app.features.settings.devices.v2.details
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.shouldBeEqualTo
import org.junit.Test
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
@ -32,7 +31,7 @@ class CheckIfSectionSessionIsVisibleUseCaseTest {
private val checkIfSectionSessionIsVisibleUseCase = CheckIfSectionSessionIsVisibleUseCase()
@Test
fun `given device info with name, id or lastSeenTs when checking is session section is visible then it returns true`() = runTest {
fun `given device info with name, id or lastSeenTs when checking is session section is visible then it returns true`() {
// Given
val deviceInfoList = listOf(
givenADeviceInfo(
@ -82,7 +81,7 @@ class CheckIfSectionSessionIsVisibleUseCaseTest {
}
@Test
fun `given device info with missing session info when checking is session section is visible then it returns true`() = runTest {
fun `given device info with missing session info when checking is session section is visible then it returns false`() {
// Given
val deviceInfoList = listOf(
givenADeviceInfo(