EmailValidator implements ConstraintValidator<Email, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (StringUtils.isEmpty(value)) { return true; } return isValidEmail(value); }  @Override boolean isValid(String value, ConstraintValidatorContext context); @Override void initialize(Email constraintAnnotation);  }
@Test public void testIsValid() { EmailValidator validator = new EmailValidator(); assertTrue(validator.isValid(null, null)); assertTrue(validator.isValid("kevin@opencirclesolutions.nl", null)); assertTrue(validator.isValid("Bob@Opencirclesolutions.nl", null)); assertTrue(validator.isValid("", null)); assertFalse(validator.isValid("ab", null)); }