JerseyExceptionMapper implements ExceptionMapper<WebApplicationException> { public Response toResponse(final WebApplicationException e) { return ErrorResponseBuilder .from(e) .build(); }  Response toResponse(final WebApplicationException e);  }
@Test public void testToResponse() { JerseyExceptionMapper mapper = new JerseyExceptionMapper(); WebApplicationException e = new WebApplicationException("test"); Response r = mapper.toResponse(e); ErrorResponse er = (ErrorResponse) r.getEntity(); assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); assertEquals(Status.INTERNAL_SERVER_ERROR, er.getHttpStatus()); assertEquals("test", er.getErrorDescription()); }
@Test public void testNotFound() { JerseyExceptionMapper mapper = new JerseyExceptionMapper(); NotFoundException e = new NotFoundException(); Response r = mapper.toResponse(e); ErrorResponse er = (ErrorResponse) r.getEntity(); assertEquals(Status.NOT_FOUND.getStatusCode(), r.getStatus()); assertEquals(Status.NOT_FOUND, er.getHttpStatus()); assertEquals("HTTP 404 Not Found", er.getErrorDescription()); assertEquals("not_found", er.getError()); }
@Test public void testForbidden() { JerseyExceptionMapper mapper = new JerseyExceptionMapper(); ForbiddenException e = new ForbiddenException(); Response r = mapper.toResponse(e); ErrorResponse er = (ErrorResponse) r.getEntity(); assertEquals(Status.FORBIDDEN.getStatusCode(), r.getStatus()); assertEquals(Status.FORBIDDEN, er.getHttpStatus()); assertEquals("HTTP 403 Forbidden", er.getErrorDescription()); assertEquals("forbidden", er.getError()); }