Updated on 2026-08-14
This commit is contained in:
parent
dcb8b474cf
commit
024a37517d
74 changed files with 103 additions and 131 deletions
1
test/core/.gitignore
vendored
Normal file
1
test/core/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
13
test/core/build.gradle.kts
Normal file
13
test/core/build.gradle.kts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
plugins {
|
||||
alias(deps.plugins.kotlin.jvm)
|
||||
id("configuration")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(deps.arrow.core)
|
||||
|
||||
api(deps.test.coroutine)
|
||||
api(deps.test.junit5)
|
||||
api(deps.test.mockk)
|
||||
api(deps.test.truth)
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.tangem.test.core
|
||||
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@MethodSource("provideTestModels")
|
||||
annotation class ProvideTestModels
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.tangem.test.core
|
||||
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun <T> TestScope.getEmittedValues(flow: Flow<T>): List<T> {
|
||||
val values = mutableListOf<T>()
|
||||
|
||||
backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) {
|
||||
flow.toList(values)
|
||||
}
|
||||
|
||||
return values
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.tangem.test.core
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.None
|
||||
import arrow.core.Option
|
||||
import com.google.common.truth.Truth
|
||||
|
||||
fun <B> assertEither(actual: Either<Throwable, B>, expected: Either<Throwable, B>) {
|
||||
actual
|
||||
.onRight { Truth.assertThat(actual).isEqualTo(expected) }
|
||||
.onLeft { throwable ->
|
||||
val expectedError = expected.leftOrNull() ?: error("Actual is Either.Left: $throwable")
|
||||
|
||||
Truth.assertThat(throwable).isInstanceOf(expectedError::class.java)
|
||||
Truth.assertThat(throwable).hasMessageThat().isEqualTo(expectedError.message)
|
||||
}
|
||||
}
|
||||
|
||||
fun assertEitherRight(actual: Either<Throwable, Unit>) {
|
||||
actual
|
||||
.onRight { Truth.assertThat(actual).isEqualTo(Either.Right(Unit)) }
|
||||
.onLeft {
|
||||
error("Actual is Either.Left: $it")
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("NullableToStringCall")
|
||||
fun <B> assertEitherLeft(actual: Either<Throwable, B>, expected: Throwable) {
|
||||
actual
|
||||
.onRight { error("Actual is Either.Right: $it") }
|
||||
.onLeft { throwable ->
|
||||
Truth.assertThat(throwable::class.java).isEqualTo(expected::class.java)
|
||||
Truth.assertThat(throwable).hasMessageThat().isEqualTo(expected.message)
|
||||
}
|
||||
}
|
||||
|
||||
fun <B> assertNone(actual: Option<B>) {
|
||||
Truth.assertThat(actual).isEqualTo(None)
|
||||
}
|
||||
|
||||
fun <B> assertSome(actual: Option<B>, expected: B) {
|
||||
actual
|
||||
.onNone { error("Actual is None") }
|
||||
.onSome {
|
||||
Truth.assertThat(it).isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue