Minor: add a unit testing utility to unwrap exceptions to their root cause.

This commit is contained in:
Mike Hearn 2016-02-26 15:29:28 +01:00
parent c24d991a7e
commit 0064f7c254

View File

@ -10,6 +10,7 @@
package core.testutils
import com.google.common.base.Throwables
import contracts.*
import core.*
import core.crypto.*
@ -23,6 +24,15 @@ import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.fail
/** If an exception is thrown by the body, rethrows the root cause exception. */
inline fun <R> rootCauseExceptions(body: () -> R) : R {
try {
return body()
} catch(e: Exception) {
throw Throwables.getRootCause(e)
}
}
object TestUtils {
val keypair = generateKeyPair()
val keypair2 = generateKeyPair()