SizePropertyValidator extends AbstractPropertyValidator<Size, String> { @Override protected boolean checkValid(String value, ConstraintValidatorContext context) { return (value != null && value.length() >= minSizeValue && value.length() <= maxSizeValue); } SizePropertyValidator(); @Override void initialize(Size constraintAnnotation);  }
@Test public void testCheckValid() throws Exception { @RemotingBean class TestedClass { @Size(min = 3, max = 8) private Property<Object> value = new MockedProperty<>(); } TestedClass bean = new TestedClass(); Set<ConstraintViolation<TestedClass>> violations; ConstraintViolation<TestedClass> violation; bean.value.set("hola"); violations = validator.validate(bean); assertEquals(violations.size(), 0); bean.value.set("holayadios"); violations = validator.validate(bean); assertEquals(violations.size(), 1); violation = violations.iterator().next(); assertEquals(violation.getPropertyPath().iterator().next().getName(), "value"); bean.value.set("ho"); violations = validator.validate(bean); assertEquals(violations.size(), 1); violation = violations.iterator().next(); assertEquals(violation.getPropertyPath().iterator().next().getName(), "value"); }