failsWith is really checking for exception class.
This commit is contained in:
@@ -3,15 +3,16 @@ package kotlin.test
|
|||||||
import java.util.ServiceLoader
|
import java.util.ServiceLoader
|
||||||
|
|
||||||
/** Asserts that a block fails with a specific exception being thrown */
|
/** Asserts that a block fails with a specific exception being thrown */
|
||||||
public fun <T: Throwable> failsWith(block: ()-> Any): T {
|
public fun <T: Throwable> failsWith(exceptionClass: Class<T>, block: ()-> Any): T {
|
||||||
try {
|
try {
|
||||||
block()
|
block()
|
||||||
asserter.fail("Expected an exception to be thrown")
|
asserter.fail("Expected an exception to be thrown")
|
||||||
throw IllegalStateException("Should have failed")
|
throw IllegalStateException("Should have failed")
|
||||||
} catch (e: T) {
|
} catch (e: T) {
|
||||||
//println("Caught expected exception: $e")
|
if (exceptionClass.isInstance(e)) {
|
||||||
// OK
|
return e
|
||||||
return e
|
}
|
||||||
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user