### Question:
MaxValidatorForString implements ConstraintValidator<Max, String> { public void initialize(Max maxValue) { this.maxValue = maxValue.value(); }  void initialize(Max maxValue); boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext);  }### Answer:
@Test public void testIsValidMax() { AnnotationDescriptor<Max> descriptor = new AnnotationDescriptor<Max>( Max.class ); descriptor.setValue( "value", 15l ); descriptor.setValue( "message", "{validator.max}" ); Max m = AnnotationFactory.create( descriptor ); MaxValidatorForString constraint = new MaxValidatorForString(); constraint.initialize( m ); testMaxValidator( constraint ); }
@Test public void testIsValidDecimalMax() { AnnotationDescriptor<DecimalMax> descriptor = new AnnotationDescriptor<DecimalMax>( DecimalMax.class ); descriptor.setValue( "value", "15.0E0" ); descriptor.setValue( "message", "{validator.max}" ); DecimalMax m = AnnotationFactory.create( descriptor ); DecimalMaxValidatorForString constraint = new DecimalMaxValidatorForString(); constraint.initialize( m ); testMaxValidator( constraint ); }
@Test public void testInitializeDecimalMaxWithInvalidValue() { AnnotationDescriptor<DecimalMax> descriptor = new AnnotationDescriptor<DecimalMax>( DecimalMax.class ); descriptor.setValue( "value", "foobar" ); descriptor.setValue( "message", "{validator.max}" ); DecimalMax m = AnnotationFactory.create( descriptor ); DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber(); try { constraint.initialize( m ); fail(); } catch ( IllegalArgumentException e ) { } }
@Test public void testInitializeDecimalMaxWithInvalidValue() { AnnotationDescriptor<DecimalMax> descriptor = new AnnotationDescriptor<DecimalMax>( DecimalMax.class ); descriptor.setValue( "value", "foobar" ); descriptor.setValue( "message", "{validator.max}" ); DecimalMax m = AnnotationFactory.create( descriptor ); DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber(); try { constraint.initialize( m ); fail(); } catch ( ConstraintDeclarationException e ) { } }