@Override
    public Response toResponse(ValidationException exception) {
        final ValidationApiError error = ValidationApiError.create("Validation failed!", exception.getErrors());
        return Response.status(Response.Status.BAD_REQUEST)
                .type(MediaType.APPLICATION_JSON_TYPE)
                .entity(error)
                .build();
    }
@Test
    public void testToResponse() throws Exception {
        final ExceptionMapper<ValidationException> mapper = new ValidationExceptionMapper();

        final Map<String, List<ValidationResult>> validationErrors = ImmutableMap.of(
                "foo", ImmutableList.of(new ValidationResult.ValidationFailed("foo failed")),
                "bar", ImmutableList.of(
                        new ValidationResult.ValidationFailed("bar failed"),
                        new ValidationResult.ValidationFailed("baz failed"))
        );

        @SuppressWarnings("ThrowableInstanceNeverThrown")
        final ValidationException exception = new ValidationException(validationErrors);
        final Response response = mapper.toResponse(exception);

        assertThat(response.getStatusInfo()).isEqualTo(Response.Status.BAD_REQUEST);
        assertThat(response.getMediaType()).isEqualTo(MediaType.APPLICATION_JSON_TYPE);
        assertThat(response.hasEntity()).isTrue();
        assertThat(response.getEntity()).isInstanceOf(ValidationApiError.class);

        final ValidationApiError responseEntity = (ValidationApiError) response.getEntity();
        assertThat(responseEntity.message()).startsWith("Validation failed!");
        assertThat(responseEntity.validationErrors()).containsKeys("foo", "bar");
        assertThat(responseEntity.validationErrors().get("foo")).hasSize(1);
        assertThat(responseEntity.validationErrors().get("bar")).hasSize(2);
    }