NotNullConstraint extends AbstractValueConstraint<Object> { @Override public Violation typedErrorFor(Object value) { return value == null ? new Violation(this, "value is null") : null; } NotNullConstraint(String theId); @Override Violation typedErrorFor(Object value); @Override String typeTag(); static final ConstraintBuilder<Object> Builder; }
@Test public void typedErrorFor() { Collection<Constraint<?>> vcs = NotNullConstraint.Builder.constraintsFrom(Schema.Type.RECORD, false, Collections.<String,String>emptyMap()); assertFalse(vcs.isEmpty()); ValueConstraint<?> constraint = (ValueConstraint<?>)vcs.iterator().next(); Violation v = constraint.errorFor("asdf"); assertNull(v); v = constraint.errorFor(null); assertNotNull(v); }