Search in sources :

Example 1 with TypedException

use of io.javalin.util.TypedException in project javalin by tipsy.

the class TestExceptionMapper method test_typedMappedException_isHandled.

@Test
public void test_typedMappedException_isHandled() throws Exception {
    app.get("/typed-exception", ctx -> {
        throw new TypedException();
    }).exception(TypedException.class, (e, ctx) -> {
        ctx.result(e.proofOfType());
    });
    HttpResponse<String> response = GET_asString("/typed-exception");
    assertThat(response.getBody(), is("I'm so typed"));
    assertThat(response.getStatus(), is(200));
}
Also used : HttpResponse(com.mashape.unirest.http.HttpResponse) TypedException(io.javalin.util.TypedException) Test(org.junit.Test) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TypedException(io.javalin.util.TypedException) Test(org.junit.Test)

Aggregations

HttpResponse (com.mashape.unirest.http.HttpResponse)1 TypedException (io.javalin.util.TypedException)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.is (org.hamcrest.Matchers.is)1 Test (org.junit.Test)1