### Question:
DigitsValidatorForString implements ConstraintValidator<Digits, String> { public void initialize(Digits constraintAnnotation) { this.maxIntegerLength = constraintAnnotation.integer(); this.maxFractionLength = constraintAnnotation.fraction(); validateParameters(); }  void initialize(Digits constraintAnnotation); boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext);  }### Answer:
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegativeIntegerLength() { AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class ); descriptor.setValue( "integer", -1 ); descriptor.setValue( "fraction", 1 ); descriptor.setValue( "message", "{validator.digits}" ); Digits p = AnnotationFactory.create( descriptor ); DigitsValidatorForString constraint = new DigitsValidatorForString(); constraint.initialize( p ); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNegativeFractionLength() { AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class ); descriptor.setValue( "integer", 1 ); descriptor.setValue( "fraction", -1 ); descriptor.setValue( "message", "{validator.digits}" ); Digits p = AnnotationFactory.create( descriptor ); DigitsValidatorForString constraint = new DigitsValidatorForString(); constraint.initialize( p ); }
@Test(expectedExceptions = ValidationException.class) public void testNegativeIntegerLength() { AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class ); descriptor.setValue( "integer", -1 ); descriptor.setValue( "fraction", 1 ); descriptor.setValue( "message", "{validator.digits}" ); Digits p = AnnotationFactory.create( descriptor ); DigitsValidatorForString constraint = new DigitsValidatorForString(); constraint.initialize( p ); }
@Test(expectedExceptions = ValidationException.class) public void testNegativeFractionLength() { AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class ); descriptor.setValue( "integer", 1 ); descriptor.setValue( "fraction", -1 ); descriptor.setValue( "message", "{validator.digits}" ); Digits p = AnnotationFactory.create( descriptor ); DigitsValidatorForString constraint = new DigitsValidatorForString(); constraint.initialize( p ); }