use of org.hibernate.validator.internal.constraintvalidators.bv.DigitsValidatorForNumber in project hibernate-validator by hibernate.
the class DigitsValidatorForNumberTest method testNegativeFractionLength.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNegativeFractionLength() {
descriptorBuilder.setAttribute("integer", 1);
descriptorBuilder.setAttribute("fraction", -1);
Digits p = descriptorBuilder.build().getAnnotation();
DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
constraint.initialize(p);
}
use of org.hibernate.validator.internal.constraintvalidators.bv.DigitsValidatorForNumber in project hibernate-validator by hibernate.
the class DigitsValidatorForNumberTest method testNegativeIntegerLength.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNegativeIntegerLength() {
descriptorBuilder.setAttribute("integer", -1);
descriptorBuilder.setAttribute("fraction", 1);
Digits p = descriptorBuilder.build().getAnnotation();
DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
constraint.initialize(p);
}
use of org.hibernate.validator.internal.constraintvalidators.bv.DigitsValidatorForNumber in project hibernate-validator by hibernate.
the class DigitsValidatorForNumberTest method testIsValid.
@Test
public void testIsValid() {
descriptorBuilder.setAttribute("integer", 5);
descriptorBuilder.setAttribute("fraction", 2);
Digits p = descriptorBuilder.build().getAnnotation();
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));
}
use of org.hibernate.validator.internal.constraintvalidators.bv.DigitsValidatorForNumber in project hibernate-validator by hibernate.
the class DigitsValidatorForNumberTest method testTrailingZerosAreTrimmed.
@Test
public void testTrailingZerosAreTrimmed() {
descriptorBuilder.setAttribute("integer", 12);
descriptorBuilder.setAttribute("fraction", 3);
Digits p = descriptorBuilder.build().getAnnotation();
DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
constraint.initialize(p);
assertTrue(constraint.isValid(0.001d, null));
assertTrue(constraint.isValid(0.00100d, null));
assertFalse(constraint.isValid(0.0001d, null));
}
use of org.hibernate.validator.internal.constraintvalidators.bv.DigitsValidatorForNumber in project hibernate-validator by hibernate.
the class DigitsValidatorForNumberTest method testIsValidZeroLength.
@Test
public void testIsValidZeroLength() {
descriptorBuilder.setAttribute("integer", 0);
descriptorBuilder.setAttribute("fraction", 0);
Digits p = descriptorBuilder.build().getAnnotation();
DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
constraint.initialize(p);
assertTrue(constraint.isValid(null, null));
assertFalse(constraint.isValid(Byte.valueOf("0"), null));
assertFalse(constraint.isValid(Double.valueOf("500.2"), null));
}
Aggregations