BytePrefixConstraint extends AbstractValueConstraint<byte[]> { @Override public Violation typedErrorFor(byte[] values) { for (SignatureMatcher matcher : matchers) { if (matcher.matches(values)) return null; } return new Violation(this, "Unable to match existing prefixes"); } protected  BytePrefixConstraint(String theId, boolean nullAllowed, SignatureMatcher... theMatchers); @Override byte[] cast(Object value); @Override Map<Parameter<?>, Object> parameters(); @Override Violation typedErrorFor(byte[] values); @Override String typeTag(); static final ByteMatcherParameter MATCHERS; static final String Docs; static final ConstraintBuilder<byte[]> Builder; }
@Test public void typedErrorFor() { Map<String,String> paramsByKey = asParams(BytePrefixConstraint.MATCHERS, "GIF"); Collection<Constraint<?>> vcs = BytePrefixConstraint.Builder.constraintsFrom(Schema.Type.BYTES, false, paramsByKey); ValueConstraint<?> vc = (ValueConstraint<?>)vcs.iterator().next(); byte[] data = readResource("throbber.gif"); Violation v = vc.errorFor(data); assertNull(v); data = readResource("32px.png"); v = vc.errorFor(data); assertNotNull(v); v = vc.errorFor(new byte[] { 0, 1, 2, 3, 4 } ); assertNotNull(v); }