@Test
public void shouldNotCrashOnNullValues() {

    // given
    final ErrorHalRepresentationFactory factory = new ErrorHalRepresentationFactory(messageSource, new ObjectMapper(), "someErrorProfile");
    // when
    final Errors mockErrors = mock(Errors.class);
    final FieldError fieldError = new FieldError("someObject",
            "xyzField",
            null,
            true,
            new String[]{"NotEmpty"},
            new Object[]{},
            "Some default message");
    when(mockErrors.getAllErrors()).thenReturn(Collections.singletonList(fieldError));
    when(mockErrors.getErrorCount()).thenReturn(1);
    final ErrorHalRepresentation errorHalRepresentation = factory.halRepresentationForValidationErrors(mockErrors);
    // then
    assertThat(errorHalRepresentation.getErrorMessage(), is("Validation failed. 1 error(s)"));
    assertThat(errorHalRepresentation.getLinks().getLinkBy("profile").isPresent(), is(true));
    assertThat(errorHalRepresentation.getLinks().getLinkBy("profile").get().getHref(), is("someErrorProfile"));
    final List<Map<String, String>> listOfViolations = errorHalRepresentation.getErrors().get("xyzField");
    assertThat(listOfViolations, hasSize(1));
    assertThat(listOfViolations.get(0), hasEntry("key", "text.not_empty"));
    assertThat(listOfViolations.get(0), hasEntry("message", "Some default message"));
    assertThat(listOfViolations.get(0), hasEntry("rejected", "null"));
}