In Java, the programmer can specify expected exceptions for JUnit test cases like this:
@Test(expected = ArithmeticException.class)
public void omg()
{
int bl
You can use @Test(expected = ArithmeticException::class)
or even better one of Kotlin's library methods like failsWith().
You can make it even shorter by using reified generics and a helper method like this:
inline fun failsWithX(noinline block: () -> Any) {
kotlin.test.failsWith(javaClass(), block)
}
And example using the annotation:
@Test(expected = ArithmeticException::class)
fun omg() {
}