dave08
05/02/2021, 2:08 PMfun <V, E> Assertion.Builder<Result<V, E>>.isFailure(): Assertion.Builder<E> =
assert("is failure") {
when {
it is Err -> pass(
description = "threw %s",
actual = it.error
)
else -> fail(
description = "returned %s",
actual = it.get()
)
}
}
.get("exception") {
unwrapError()
}
fun <V, E> Assertion.Builder<Result<V, E>>.isSuccess(): Assertion.Builder<V> =
assert("is success") {
when {
it is Ok -> pass()
else -> fail(
description = "was error ${it.unwrapError()}",
)
}
}
.get("value") {
unwrap()
}
inline fun <reified E> Assertion.Builder<Result<Any?, E>>.failedWith() =
isFailure().isA<E>()
But when I try `
expectThat(result).isFailure().isA<SomeDomainError>()
I get:
org.opentest4j.AssertionFailedError: ▼ Expect that Ok(SomeStub(id=1,...)):
✗ is failure
returned SomeStub(id=1, ...)
robfletcher
05/02/2021, 2:10 PMkotlin.Result
extensionsdave08
05/02/2021, 2:11 PMrobfletcher
05/02/2021, 2:13 PMrobfletcher
05/02/2021, 2:13 PMdave08
05/02/2021, 2:17 PM%s
... so that's ok... but I still have a problem with the
inline fun <reified E> Assertion.Builder<Result<Any?, E>>.failedWith() =
isFailure().isA<E>()
not working, it has a problem with receiver types not matching...dave08
05/02/2021, 2:20 PM.isA<SomeDomainError>()
dave08
05/02/2021, 2:24 PMfailedWith()
wouldn't help with that...