BlacklistValidation implements FormItemValidation<Object> { @Override public ValidationResult validate(final Object value) { if (value == null || String.valueOf(value).trim().length() == 0) { return ValidationResult.OK; } else { return blacklist.contains(value) ? ValidationResult.invalid(errorMessage()) : ValidationResult.OK; } } BlacklistValidation(final String first, final String... rest);  BlacklistValidation(Iterable<String> blacklist); @Override ValidationResult validate(final Object value);  }
@Test public void validateNull() { assertSame(ValidationResult.OK, blacklistValidation.validate(null)); }
@Test public void validateEmpty() { assertSame(ValidationResult.OK, blacklistValidation.validate("")); }
@Test public void validateBlank() { assertSame(ValidationResult.OK, blacklistValidation.validate(" ")); }
@Test public void validateOk() { assertSame(ValidationResult.OK, blacklistValidation.validate("ok")); }
@Test public void invalid() { assertFalse(blacklistValidation.validate("foo").isValid()); assertFalse(blacklistValidation.validate("bar").isValid()); }