ValidateAnnotationConstraintGenerator implements ValidationConstraintGenerator { public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider) { Validate annotation = annotationProvider.getAnnotation(Validate.class); if (annotation == null) return null; return Arrays.asList(validatorPattern.split(annotation.value())); } ValidateAnnotationConstraintGenerator(); List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider);  }
@Test public void no_annotation() { PropertyConduit conduit = mockPropertyConduit(); train_getAnnotation(conduit, Validate.class, null); replay(); ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator(); assertNull(gen.buildConstraints(Object.class, conduit)); verify(); }
@Test public void single_constraint() { PropertyConduit conduit = mockPropertyConduit(); Validate validate = newValidate("required"); train_getAnnotation(conduit, Validate.class, validate); replay(); ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator(); assertEquals(gen.buildConstraints(Object.class, conduit), Arrays.asList("required")); verify(); }
@Test public void multiple_constraints() { PropertyConduit conduit = mockPropertyConduit(); Validate validate = newValidate("required,minlength=3,regexp=^([a-zA-Z0-9]{2,4})+$"); train_getAnnotation(conduit, Validate.class, validate); replay(); ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator(); assertEquals(gen.buildConstraints(null, conduit), Arrays.asList("required", "minlength=3", "regexp=^([a-zA-Z0-9]{2,4})+$")); verify(); }
@Test public void regex_ranges_constraints() { PropertyConduit conduit = mockPropertyConduit(); Validate validate = newValidate("regexp=^([a]{50,125}[0-9]{2,4})+$,required,567matcher,regexp=a\\,b,regexp=a{1,}"); train_getAnnotation(conduit, Validate.class, validate); replay(); ValidationConstraintGenerator gen = new ValidateAnnotationConstraintGenerator(); assertEquals(gen.buildConstraints(null, conduit), Arrays.asList("regexp=^([a]{50,125}[0-9]{2,4})+$","required", "567matcher", "regexp=a\\,b", "regexp=a{1,}")); verify(); }