### Question:
LengthValidator implements ConstraintValidator<Length, String> { public void initialize(Length parameters) { min = parameters.min(); max = parameters.max(); validateParameters(); }  void initialize(Length parameters); boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext);  }### Answer:
@Test(expectedExceptions = ValidationException.class) public void testNegativeMinValue() { AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class ); descriptor.setValue( "min", -1 ); descriptor.setValue( "max", 1 ); descriptor.setValue( "message", "{validator.length}" ); Length p = AnnotationFactory.create( descriptor ); LengthValidator constraint = new LengthValidator(); constraint.initialize( p ); }
@Test(expectedExceptions = ValidationException.class) public void testNegativeMaxValue() { AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class ); descriptor.setValue( "min", 1 ); descriptor.setValue( "max", -1 ); descriptor.setValue( "message", "{validator.length}" ); Length p = AnnotationFactory.create( descriptor ); LengthValidator constraint = new LengthValidator(); constraint.initialize( p ); }
@Test(expectedExceptions = ValidationException.class) public void testNegativeLength() { AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class ); descriptor.setValue( "min", 5 ); descriptor.setValue( "max", 4 ); descriptor.setValue( "message", "{validator.length}" ); Length p = AnnotationFactory.create( descriptor ); LengthValidator constraint = new LengthValidator(); constraint.initialize( p ); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegativeMinValue() { AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class ); descriptor.setValue( "min", -1 ); descriptor.setValue( "max", 1 ); descriptor.setValue( "message", "{validator.length}" ); Length p = AnnotationFactory.create( descriptor ); LengthValidator constraint = new LengthValidator(); constraint.initialize( p ); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegativeMaxValue() { AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class ); descriptor.setValue( "min", 1 ); descriptor.setValue( "max", -1 ); descriptor.setValue( "message", "{validator.length}" ); Length p = AnnotationFactory.create( descriptor ); LengthValidator constraint = new LengthValidator(); constraint.initialize( p ); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegativeLength() { AnnotationDescriptor<Length> descriptor = new AnnotationDescriptor<Length>( Length.class ); descriptor.setValue( "min", 5 ); descriptor.setValue( "max", 4 ); descriptor.setValue( "message", "{validator.length}" ); Length p = AnnotationFactory.create( descriptor ); LengthValidator constraint = new LengthValidator(); constraint.initialize( p ); }