kotlin-test: Make assertFailsWith(KClass<T: Throwable>) common
This commit is contained in:
@@ -33,19 +33,17 @@ private fun <T : Throwable> assertFailsWithImpl(exceptionClass: Class<T>, messag
|
||||
}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER")
|
||||
asserter.fail(messagePrefix(message) + "Expected an exception of type $exceptionClass to be thrown, but was $e")
|
||||
asserter.fail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was $e")
|
||||
}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER")
|
||||
val msg = messagePrefix(message)
|
||||
asserter.fail(msg + "Expected an exception of type $exceptionClass to be thrown, but was completed successfully.")
|
||||
asserter.fail(msg + "Expected an exception of $exceptionClass to be thrown, but was completed successfully.")
|
||||
}
|
||||
|
||||
/** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */
|
||||
fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block)
|
||||
|
||||
/** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */
|
||||
fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T = assertFailsWithImpl(exceptionClass.java, message, block)
|
||||
impl fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T = assertFailsWithImpl(exceptionClass.java, message, block)
|
||||
|
||||
/*
|
||||
/** Asserts that a [block] fails with a specific exception of type [T] being thrown.
|
||||
|
||||
@@ -4,26 +4,7 @@ import kotlin.test.*
|
||||
import org.junit.*
|
||||
|
||||
class BasicAssertionsJVMTest {
|
||||
@Test
|
||||
fun testFailsWith() {
|
||||
assertFailsWith(IllegalArgumentException::class) {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError::class)
|
||||
fun testFailsWithFails() {
|
||||
assertFailsWith(IllegalArgumentException::class) {
|
||||
throw IllegalStateException()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFailsWithMessage() {
|
||||
assertFailsWith<IllegalArgumentException>() {
|
||||
throw IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun testFailsWithClassMessage() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
Reference in New Issue
Block a user