### Question:
DigitsValidatorForString implements ConstraintValidator<Digits, String> { public boolean isValid(String str, ConstraintValidatorContext constraintValidatorContext) { if ( str == null ) { return true; } BigDecimal bigNum = getBigDecimalValue( str ); if ( bigNum == null ) { return false; } 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(String str, ConstraintValidatorContext constraintValidatorContext);  }### Answer:
@Test public void testIsValid() { assertTrue( constraint.isValid( null, null ) ); assertTrue( constraint.isValid( "0", null ) ); assertTrue( constraint.isValid( "500.2", null ) ); assertTrue( constraint.isValid( "-12456.22", null ) ); assertTrue( constraint.isValid( "-000000000.22", null ) ); assertFalse( constraint.isValid( "", null ) ); assertFalse( constraint.isValid( "256874.0", null ) ); assertFalse( constraint.isValid( "12.0001", null ) ); }