InstantValidator implements ConstraintValidator<IsInstant, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (value == null) { return true; } try { Instant.parse(value); } catch (DateTimeParseException e){ return false; } return true; }  @Override void initialize(IsInstant constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context);  }
@Test public void shouldReturnFalseIfInstantIsNotParseable() { final InstantValidator subject = new InstantValidator(); final boolean result = subject.isValid("blabla", null); assertThat(result, is(false)); }
@Test public void shouldReturnTrueIfInstantIsParseable() { final InstantValidator subject = new InstantValidator(); final boolean result = subject.isValid("2042-02-05T10:17:38.858Z", null); assertThat(result, is(true)); }
@Test public void shouldReturnTrueIfInstantIsNull() { final InstantValidator subject = new InstantValidator(); final boolean result = subject.isValid(null, null); assertThat(result, is(true)); }