Question: In Java, the programmer can specify expected exceptions for JUnit test cases like this:

```
@Test(expected = ArithmeticException.class)
public void omg()
{
    int blackHole = 1 / 0;
}

```

How would I do this in Kotlin? I have tried two syntax variations, but none of them worked:

```
import org.junit.Test

// ...

@Test(expected = ArithmeticException) fun omg()
    Please specify constructor invocation;
    classifier 'ArithmeticException' does not have a companion object

@Test(expected = ArithmeticException.class) fun omg()
                            name expected ^
                                            ^ expected ')'

```

Answer: 
You can use `@Test(expected = ArithmeticException::class)` or even better one of Kotlin's library methods like [`failsWith()`](http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.test/fails-with.html).

You can make it even shorter by using reified generics and a helper method like this:

```
inline fun <reified T : Throwable> failsWithX(noinline block: () -> Any) {
    kotlin.test.failsWith(javaClass<T>(), block)
}

```

And example using the annotation:

```
@Test(expected = ArithmeticException::class)
fun omg() {

}

```
Firt steps is to add `(expected = YourException::class)` in test annotation

```
@Test(expected = YourException::class)

```

Second step is to add this function

```
private fun throwException(): Boolean = throw YourException()

```

Finally you will have something like this:

```
@Test(expected = ArithmeticException::class)
fun `get query error from assets`() {
    //Given
    val error = "ArithmeticException"

    //When
    throwException()
    val result =  omg()

    //Then
    Assert.assertEquals(result, error)
}
private fun throwException(): Boolean = throw ArithmeticException()

```