failsWith is really checking for exception class.

This commit is contained in:
Evgeny Gerashchenko
2013-01-29 20:43:26 +04:00
parent 66ce736a81
commit 719ed4c795
+5 -4
View File
@@ -3,15 +3,16 @@ package kotlin.test
import java.util.ServiceLoader
/** 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 {
block()
asserter.fail("Expected an exception to be thrown")
throw IllegalStateException("Should have failed")
} catch (e: T) {
//println("Caught expected exception: $e")
// OK
return e
if (exceptionClass.isInstance(e)) {
return e
}
throw e
}
}