IllegalCharacterConstraint extends AbstractStringConstraint { @Override public Violation typedErrorFor(String value) { int len = value.length(); if (len == 0) return null; for (int i=0; i<len; i++) { char ch = value.charAt(i); if (isIllegal(ch)) { return new Violation(this, "Illegal character: " + ch); } } return null; } IllegalCharacterConstraint(String theId, boolean nullAllowed, char...  theChars);  IllegalCharacterConstraint(String theId, boolean nullAllowed, String theIllegals); @Override Violation typedErrorFor(String value); @Override String typeTag(); static final String TypeTag; static final String Docs; static final StringParameter BAD_CHARS; static final ConstraintBuilder<String> Builder; }
@Test public void typedErrorFor() { Map<String,String> paramsByKey = asParams(IllegalCharacterConstraint.BAD_CHARS, "./?"); Collection<Constraint<?>> vcs = IllegalCharacterConstraint.Builder.constraintsFrom(Schema.Type.STRING, false, paramsByKey); ValueConstraint<?> vc = (ValueConstraint<?>)vcs.iterator().next(); Violation violation = vc.errorFor("hello world"); assertNull(violation); violation = vc.errorFor(""); assertNull(violation); violation = vc.errorFor("hello world?"); assertNotNull(violation); violation = vc.errorFor(".hello world?"); assertNotNull(violation); }