ByteArraySizeConstraint extends AbstractValueConstraint<byte[]> { @Override public Map<Parameter<?>, Object> parameters() { Map<Parameter<?>, Object> params = new HashMap<>(2); if (minSize != null) params.put(MIN_SIZE, minSize); if (maxSize != null) params.put(MAX_SIZE, maxSize); return params; } protected  ByteArraySizeConstraint(String theId, boolean nullAllowed, Integer theMinSize, Integer theMaxSize); @Override Map<Parameter<?>, Object> parameters(); @Override byte[] cast(Object value); @Override Violation typedErrorFor(byte[] values); @Override String typeTag(); static final IntegerParameter MIN_SIZE; static final IntegerParameter MAX_SIZE; static final ConstraintBuilder<byte[]> Builder; }
@Test public void testBuilder() { Map<String,String> paramsByKey = asParams(ByteArraySizeConstraint.MIN_SIZE, 2, ByteArraySizeConstraint.MAX_SIZE, 4); Map<String,String> paramsCopy = new HashMap<>(); paramsCopy.putAll(paramsByKey); Collection<Constraint<?>> vcs = ByteArraySizeConstraint.Builder.constraintsFrom(Schema.Type.BYTES, false, paramsByKey); assertNotNull(vcs); assertEquals(1, vcs.size()); ValueConstraint<?> vc = (ValueConstraint<?>)vcs.iterator().next(); assertEquals(paramsCopy.size(), vc.parameters().size()); }