TimestampRangeConstraint extends AbstractValueConstraint<Long> { @Override public Violation typedErrorFor(Long value) { if (minTimestamp != null && minTimestamp > value) { return new Violation(this, MIN_TIMESTAMP.asString(value) + " is too early, earliest is " + MIN_TIMESTAMP.asString(minTimestamp)); } if (maxTimestamp != null && maxTimestamp < value) { return new Violation(this, MAX_TIMESTAMP.asString(value) + " is too late, latest is " + MAX_TIMESTAMP.asString(maxTimestamp)); } return null; } TimestampRangeConstraint(String theId, boolean nullAllowed, String theMin, String theMax);  TimestampRangeConstraint(String theId, boolean nullAllowed, Long theMin, Long theMax); @Override String typeTag(); @Override Map<Parameter<?>, Object> parameters(); @Override Violation typedErrorFor(Long value); static final String TypeTag; static final String Docs; static final ConstraintBuilder<Long> Builder; }
@Test public void typedErrorFor() { Map<String,String> paramsByKey = asParams( TimestampRangeConstraint.MIN_TIMESTAMP, "2016-02-01 00:00:00", TimestampRangeConstraint.MAX_TIMESTAMP, "2016-03-01 00:00:00"); Collection<Constraint<?>> vcs = TimestampRangeConstraint.Builder.constraintsFrom(Schema.Type.LONG, false, paramsByKey); TimestampRangeConstraint trc = (TimestampRangeConstraint)vcs.iterator().next(); long midMonth = TimestampRangeConstraint.MIN_TIMESTAMP.valueIn("2016-02-15 00:00:00", null); Violation violation = trc.typedErrorFor(midMonth); assertNull(violation); long nextMonth = TimestampRangeConstraint.MIN_TIMESTAMP.valueIn("2016-04-01 00:00:00", null); violation = trc.typedErrorFor(nextMonth); assertNotNull(violation); }