@SuppressWarnings({ "unchecked", "rawtypes" })

@Test
public void constraintViolationExceptionCausesBadRequest() {
  Path violationPath = mock(Path.class);
  when(violationPath.toString()).thenReturn("violationPath");
  ConstraintViolation violation = mock(ConstraintViolation.class);
  when(violation.getRootBeanClass()).thenReturn(CustomValidationExceptionMapperTest.class);
  when(violation.getPropertyPath()).thenReturn(violationPath);
  when(violation.getMessage()).thenReturn("violationMessage");
  ConstraintViolationException exception = mock(ConstraintViolationException.class);
  when(exception.getConstraintViolations()).thenReturn(new LinkedHashSet(asList(violation)));
  try (Response response = exceptionMapper.toResponse(exception)) {
    assertThat(response.getStatus(), is(BAD_REQUEST.getStatusCode()));
    ErrorResponse error = (ErrorResponse) response.getEntity();
    assertThat(error.error, is("violationPath: violationMessage"));
  }
}