Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ExpectedException with Kotlin

Tags:

java

junit

kotlin

I've declared an expected exception with Kotlin:

@Rule
public var exception = ExpectedException.none()

Now my integration test case:

@Test
@Transactional
fun authorize_withInvalidToken()
{
    val response = controller.authorize(networkType = "facebook", oauthToken = "", oauthTokenSecret = null)
    exception.expect(UnauthorizedException::class.java)

}

I get the error:

org.junit.internal.runners.rules.ValidationError: The @Rule 'exception' must be public.

Is there a way to fix this? For now I'll just use manual try/catch/assert

like image 902
Jasper Blues Avatar asked Oct 31 '15 06:10

Jasper Blues


1 Answers

Annotate the exception property with @JvmField:

@Rule
@JvmField
var exception = ExpectedException.none()
like image 106
JB Nizet Avatar answered Sep 19 '22 18:09

JB Nizet