Search in sources :

Example 1 with MaxValidatorForNumber

use of org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForNumber in project hibernate-validator by hibernate.

the class MaxValidatorForNumberTest method testMax.

private void testMax(Max m, boolean inclusive) {
    AbstractMaxValidator constraint = new MaxValidatorForNumber();
    constraint.initialize(m);
    testNumberValidator(constraint, inclusive, true);
    constraint = new MaxValidatorForBigDecimal();
    constraint.initialize(m);
    testValidatorBigDecimal(constraint, inclusive, true);
    constraint = new MaxValidatorForBigInteger();
    constraint.initialize(m);
    testValidatorBigInteger(constraint, inclusive, true);
    constraint = new MaxValidatorForByte();
    constraint.initialize(m);
    testValidatorByte(constraint, inclusive, true);
    constraint = new MaxValidatorForShort();
    constraint.initialize(m);
    testValidatorShort(constraint, inclusive, true);
    constraint = new MaxValidatorForInteger();
    constraint.initialize(m);
    testValidatorInteger(constraint, inclusive, true);
    constraint = new MaxValidatorForLong();
    constraint.initialize(m);
    testValidatorLong(constraint, inclusive, true);
    constraint = new MaxValidatorForFloat();
    constraint.initialize(m);
    testValidatorFloat(constraint, inclusive, true);
    constraint = new MaxValidatorForDouble();
    constraint.initialize(m);
    testValidatorDouble(constraint, inclusive, true);
}
Also used : MaxValidatorForLong(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForLong) DecimalMaxValidatorForLong(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForLong) MaxValidatorForByte(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForByte) DecimalMaxValidatorForByte(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForByte) MaxValidatorForBigInteger(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForBigInteger) DecimalMaxValidatorForBigInteger(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigInteger) MaxValidatorForDouble(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForDouble) DecimalMaxValidatorForDouble(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForDouble) MaxValidatorForFloat(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForFloat) DecimalMaxValidatorForFloat(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForFloat) AbstractMaxValidator(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.AbstractMaxValidator) MaxValidatorForBigDecimal(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForBigDecimal) DecimalMaxValidatorForBigDecimal(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigDecimal) MaxValidatorForInteger(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForInteger) DecimalMaxValidatorForInteger(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForInteger) DecimalMaxValidatorForNumber(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForNumber) MaxValidatorForNumber(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForNumber) MaxValidatorForShort(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForShort) DecimalMaxValidatorForShort(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForShort)

Example 2 with MaxValidatorForNumber

use of org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForNumber in project hibernate-validator by hibernate.

the class MaxValidatorForNumberTest method testIsValidNumberForFloatingPointOrBigNumbersStoredAsNumber.

@Test
@TestForIssue(jiraKey = "HV-1699")
public void testIsValidNumberForFloatingPointOrBigNumbersStoredAsNumber() {
    ConstraintAnnotationDescriptor.Builder<Max> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(Max.class);
    descriptorBuilder.setAttribute("value", 1L);
    Max m = descriptorBuilder.build().getAnnotation();
    MaxValidatorForNumber validator = new MaxValidatorForNumber();
    validator.initialize(m);
    assertFalse(validator.isValid(1.01, null));
    assertFalse(validator.isValid(1.01F, null));
    assertFalse(validator.isValid(new BigDecimal("1.01"), null));
    assertFalse(validator.isValid(new BigInteger("2"), null));
    assertFalse(validator.isValid(Double.POSITIVE_INFINITY, null));
    assertFalse(validator.isValid(Float.POSITIVE_INFINITY, null));
}
Also used : ConstraintAnnotationDescriptor(org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor) DecimalMax(jakarta.validation.constraints.DecimalMax) Max(jakarta.validation.constraints.Max) BigInteger(java.math.BigInteger) MaxValidatorForBigInteger(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForBigInteger) DecimalMaxValidatorForBigInteger(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigInteger) BigDecimal(java.math.BigDecimal) MaxValidatorForBigDecimal(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForBigDecimal) DecimalMaxValidatorForBigDecimal(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigDecimal) DecimalMaxValidatorForNumber(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForNumber) MaxValidatorForNumber(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForNumber) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Aggregations

MaxValidatorForBigDecimal (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForBigDecimal)2 MaxValidatorForBigInteger (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForBigInteger)2 MaxValidatorForNumber (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForNumber)2 DecimalMaxValidatorForBigDecimal (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigDecimal)2 DecimalMaxValidatorForBigInteger (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigInteger)2 DecimalMaxValidatorForNumber (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForNumber)2 DecimalMax (jakarta.validation.constraints.DecimalMax)1 Max (jakarta.validation.constraints.Max)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 AbstractMaxValidator (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.AbstractMaxValidator)1 MaxValidatorForByte (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForByte)1 MaxValidatorForDouble (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForDouble)1 MaxValidatorForFloat (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForFloat)1 MaxValidatorForInteger (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForInteger)1 MaxValidatorForLong (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForLong)1 MaxValidatorForShort (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.MaxValidatorForShort)1 DecimalMaxValidatorForByte (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForByte)1 DecimalMaxValidatorForDouble (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForDouble)1 DecimalMaxValidatorForFloat (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForFloat)1