DataNotFoundExceptionMapper implements ExceptionMapper<DataNotFoundException> { @Override public Response toResponse(DataNotFoundException e) { return Response.status(404) .type(MediaType.APPLICATION_JSON_TYPE) .entity(ImmutableMap.of("code", 404, "message", e.getMessage())) .build(); }  @Override Response toResponse(DataNotFoundException e);  }
@Test public void toResponse() throws Exception { DataNotFoundExceptionMapper mapper = new DataNotFoundExceptionMapper(); Response response = mapper.toResponse(new DataNotFoundException("not found")); assertEquals(404, response.getStatus()); assertEquals("application/json", response.getMediaType().toString()); @SuppressWarnings("unchecked") Map<String,Object> map = (Map<String,Object>)response.getEntity(); assertEquals(404, map.get("code")); assertEquals("not found", map.get("message")); }