TimestampEraConstraint extends AbstractValueConstraint<Long> { @Override public Violation typedErrorFor(Long value) { switch (restriction) { case Future : return checkFuture(value); case Historical : return checkHistorical(value); } return null; } TimestampEraConstraint(String theId, boolean nullAllowed, TimestampRestriction theRestriction); @Override String typeTag(); @Override Violation typedErrorFor(Long value); @Override Map<Parameter<?>, Object> parameters(); static final String TypeTag; static final String Docs; static final StringParameter Era; static final ConstraintBuilder<Long> Builder; }
@Test public void typedErrorFor() { Map<String,String> paramsByKey = asParams(TimestampEraConstraint.Era, TimestampRestriction.Historical); Collection<Constraint<?>> vcs = TimestampEraConstraint.Builder.constraintsFrom(Schema.Type.LONG, false, paramsByKey); ValueConstraint<?> vc = (ValueConstraint<?>)vcs.iterator().next(); Violation violation = vc.errorFor(System.currentTimeMillis() - 1000); assertNull(violation); violation = vc.errorFor(System.currentTimeMillis() + 1000); assertNotNull(violation); paramsByKey = asParams(TimestampEraConstraint.Era, TimestampRestriction.Future); vcs = TimestampEraConstraint.Builder.constraintsFrom(Schema.Type.LONG, false, paramsByKey); vc = (ValueConstraint<?>)vcs.iterator().next(); violation = vc.errorFor(System.currentTimeMillis() - 1000); assertNotNull(violation); violation = vc.errorFor(System.currentTimeMillis() + 1000); assertNull(violation); }