EmailValidator implements Validator<String> { @Override public ValidationResult apply(String value, ValueContext context) { if (StringUtils.isEmpty(value)) { return ValidationResult.ok(); } if (!value.toLowerCase().matches(EMAIL_PATTERN)) { return ValidationResult.error(message); } return ValidationResult.ok(); } EmailValidator(String message); @Override ValidationResult apply(String value, ValueContext context);  }
@Test public void test() { EmailValidator validator = new EmailValidator("message"); ValidationResult res = validator.apply(null, new ValueContext()); assertFalse(res.isError()); res = validator.apply("", new ValueContext()); assertFalse(res.isError()); res = validator.apply("test@test.nl", new ValueContext()); assertFalse(res.isError()); res = validator.apply("bogus", new ValueContext()); assertTrue(res.isError()); }