KangarooErrorPageGenerator implements ErrorPageGenerator { @Override public String generate(final Request request, final int status, final String reasonPhrase, final String description, final Throwable exception) { Response r = request.getResponse(); r.setContentType(MediaType.APPLICATION_JSON); ErrorResponse body = ErrorResponseBuilder .from(Status.fromStatusCode(status), description) .buildEntity(); try { return getMapper().writeValueAsString(body); } catch (JsonProcessingException jpe) { return "{\"error\":\"internal_server_error\"," + "\"error_description\":\"Internal Server Error\"}"; } }  ObjectMapper getMapper(); @Override String generate(final Request request,
                           final int status,
                           final String reasonPhrase,
                           final String description,
                           final Throwable exception);  }
@Test public void assertBasicError() throws Exception { KangarooErrorPageGenerator generator = new KangarooErrorPageGenerator(); Request r = mock(Request.class); Response response = mock(Response.class); doReturn(response) .when(r) .getResponse(); String body = generator.generate(r, 404, "Not Found", "Not Found", null); ErrorResponse decoded = MAPPER.readValue(body, ErrorResponse.class); assertEquals("not_found", decoded.getError()); assertEquals("Not Found", decoded.getErrorDescription()); verify(response, times(1)) .setContentType(MediaType.APPLICATION_JSON); }