@Test
@SuppressWarnings("unchecked")
public void toResponse() throws Exception {

    DataValidationExceptionMapper mapper = new DataValidationExceptionMapper();
    DataValidationException exception = new DataValidationException(Arrays.asList(ValidationError.of("field", "is invalid")));
    Response response = mapper.toResponse(exception);
    assertEquals(400, response.getStatus());
    assertEquals("application/json", response.getMediaType().toString());
    Map<String,Object> map = (Map<String,Object>)response.getEntity();
    assertEquals(400, map.get("code"));
    assertEquals("field: is invalid", map.get("message"));
    assertEquals("field", ((List<ValidationError>)map.get("errors")).get(0).getField());
}