### Question:
LengthValidator implements ConstraintValidator<Length, String> { public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { if ( value == null ) { return true; } int length = value.length(); return length >= min && length <= max; }  void initialize(Length parameters); boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext);  }### Answer:
@Test public void testIsValid() { AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class ); descriptor.setValue( "min", 1 ); descriptor.setValue( "max", 3 ); descriptor.setValue( "message", "{validator.length}" ); Length l = AnnotationFactory.create( descriptor ); LengthValidator constraint = new LengthValidator(); constraint.initialize( l ); assertTrue( constraint.isValid( null, null ) ); assertFalse( constraint.isValid( "", null ) ); assertTrue( constraint.isValid( "f", null ) ); assertTrue( constraint.isValid( "fo", null ) ); assertTrue( constraint.isValid( "foo", null ) ); assertFalse( constraint.isValid( "foobar", null ) ); }