Jasper Blues
Jasper Blues

Reputation: 28746

Use ExpectedException with 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

Upvotes: 12

Views: 3206

Answers (1)

JB Nizet
JB Nizet

Reputation: 691645

Annotate the exception property with @JvmField:

@Rule
@JvmField
var exception = ExpectedException.none()

Upvotes: 23

Related Questions