cleanup ThrowableAssertionsSpec in infix API (use WithAsciiReporter)

This commit is contained in:
Robert Stoll
2020-03-06 08:20:11 +01:00
parent 4c72123ed4
commit 133148daa7

View File

@@ -2,25 +2,18 @@ package ch.tutteli.atrium.api.infix.en_GB
import ch.tutteli.atrium.creating.Expect
import ch.tutteli.atrium.specs.*
import ch.tutteli.atrium.specs.testutils.WithAsciiReporter
import ch.tutteli.atrium.specs.withFeatureSuffix
class ThrowableAssertionsSpec : ch.tutteli.atrium.specs.integration.ThrowableAssertionsSpec(
property<Throwable, String>(Expect<Throwable>::message),
fun1<Throwable, Expect<String>.() -> Unit>(Expect<Throwable>::message),
fun2(::messageContains),
("cause" to Companion::causeFeature).withFeatureSuffix(),
"cause" to Companion::cause
("cause" to ::causeFeature).withFeatureSuffix(),
"cause" to ::cause
) {
companion object {
@Suppress("RemoveExplicitTypeArguments")
private fun causeFeature(expect: Expect<out Throwable>): Expect<IllegalArgumentException> = expect.cause<IllegalArgumentException>()
@Suppress("RemoveExplicitTypeArguments")
private fun cause(expect: Expect<out Throwable>, assertionCreator: Expect<IllegalArgumentException>.() -> Unit) =
expect.cause<IllegalArgumentException>(assertionCreator)
}
companion object : WithAsciiReporter()
@Suppress("unused", "UNUSED_VALUE")
private fun ambiguityTest() {
@@ -33,10 +26,18 @@ class ThrowableAssertionsSpec : ch.tutteli.atrium.specs.integration.ThrowableAss
a1 = a1 messageContains Values("a", 1, 'b')
a1.cause<ClassCastException>()
a1.cause<ClassCastException> { message { }}
a1.cause<ClassCastException> { message { } }
}
}
private fun messageContains(expect: Expect<Throwable>, expected: Any, vararg otherExpected: Any): Expect<Throwable> =
if (otherExpected.isEmpty()) expect messageContains expected
else expect messageContains Values(expected, *otherExpected)
@Suppress("RemoveExplicitTypeArguments")
private fun causeFeature(expect: Expect<out Throwable>): Expect<IllegalArgumentException> =
expect.cause<IllegalArgumentException>()
@Suppress("RemoveExplicitTypeArguments")
private fun cause(expect: Expect<out Throwable>, assertionCreator: Expect<IllegalArgumentException>.() -> Unit) =
expect.cause<IllegalArgumentException>(assertionCreator)