### Question:
DigitsValidatorForNumber implements ConstraintValidator<Digits, Number> { public boolean isValid(Number num, ConstraintValidatorContext constraintValidatorContext) { if ( num == null ) { return true; } BigDecimal bigNum; if ( num instanceof BigDecimal ) { bigNum = ( BigDecimal ) num; } else { bigNum = new BigDecimal( num.toString() ).stripTrailingZeros(); } int integerPartLength = bigNum.precision() - bigNum.scale(); int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale(); return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength ); }  void initialize(Digits constraintAnnotation); boolean isValid(Number num, ConstraintValidatorContext constraintValidatorContext);  }### Answer:
@Test public void testIsValid() { AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class ); descriptor.setValue( "integer", 5 ); descriptor.setValue( "fraction", 2 ); descriptor.setValue( "message", "{validator.digits}" ); Digits p = AnnotationFactory.create( descriptor ); DigitsValidatorForNumber constraint = new DigitsValidatorForNumber(); constraint.initialize( p ); assertTrue( constraint.isValid( null, null ) ); assertTrue( constraint.isValid( Byte.valueOf( "0" ), null ) ); assertTrue( constraint.isValid( Double.valueOf( "500.2" ), null ) ); assertTrue( constraint.isValid( new BigDecimal( "-12345.12" ), null ) ); assertFalse( constraint.isValid( new BigDecimal( "-123456.12" ), null ) ); assertFalse( constraint.isValid( new BigDecimal( "-123456.123" ), null ) ); assertFalse( constraint.isValid( new BigDecimal( "-12345.123" ), null ) ); assertFalse( constraint.isValid( new BigDecimal( "12345.123" ), null ) ); assertTrue( constraint.isValid( Float.valueOf( "-000000000.22" ), null ) ); assertFalse( constraint.isValid( Integer.valueOf( "256874" ), null ) ); assertFalse( constraint.isValid( Double.valueOf( "12.0001" ), null ) ); }