Search in sources :

Example 1 with DecimalMaxValidatorForNumber

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

the class MaxValidatorForNumberTest method testDecimalMax.

private void testDecimalMax(DecimalMax m, boolean inclusive) {
    AbstractDecimalMaxValidator constraint = new DecimalMaxValidatorForNumber();
    constraint.initialize(m);
    testNumberValidator(constraint, inclusive, true);
    constraint = new DecimalMaxValidatorForBigDecimal();
    constraint.initialize(m);
    testValidatorBigDecimal(constraint, inclusive, true);
    constraint = new DecimalMaxValidatorForBigInteger();
    constraint.initialize(m);
    testValidatorBigInteger(constraint, inclusive, true);
    constraint = new DecimalMaxValidatorForByte();
    constraint.initialize(m);
    testValidatorByte(constraint, inclusive, true);
    constraint = new DecimalMaxValidatorForShort();
    constraint.initialize(m);
    testValidatorShort(constraint, inclusive, true);
    constraint = new DecimalMaxValidatorForInteger();
    constraint.initialize(m);
    testValidatorInteger(constraint, inclusive, true);
    constraint = new DecimalMaxValidatorForLong();
    constraint.initialize(m);
    testValidatorLong(constraint, inclusive, true);
    constraint = new DecimalMaxValidatorForFloat();
    constraint.initialize(m);
    testValidatorFloat(constraint, inclusive, true);
    constraint = new DecimalMaxValidatorForDouble();
    constraint.initialize(m);
    testValidatorDouble(constraint, inclusive, true);
}
Also used : AbstractDecimalMaxValidator(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.AbstractDecimalMaxValidator) DecimalMaxValidatorForFloat(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForFloat) DecimalMaxValidatorForNumber(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForNumber) DecimalMaxValidatorForShort(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForShort) DecimalMaxValidatorForBigDecimal(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigDecimal) DecimalMaxValidatorForInteger(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForInteger) DecimalMaxValidatorForByte(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForByte) DecimalMaxValidatorForLong(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForLong) DecimalMaxValidatorForBigInteger(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigInteger) DecimalMaxValidatorForDouble(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForDouble)

Example 2 with DecimalMaxValidatorForNumber

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

the class MaxValidatorForNumberTest method testInitializeDecimalMaxWithInvalidValue.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testInitializeDecimalMaxWithInvalidValue() {
    ConstraintAnnotationDescriptor.Builder<DecimalMax> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(DecimalMax.class);
    descriptorBuilder.setAttribute("value", "foobar");
    descriptorBuilder.setMessage("{validator.max}");
    DecimalMax m = descriptorBuilder.build().getAnnotation();
    DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber();
    constraint.initialize(m);
}
Also used : ConstraintAnnotationDescriptor(org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor) DecimalMaxValidatorForNumber(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForNumber) DecimalMax(jakarta.validation.constraints.DecimalMax) Test(org.testng.annotations.Test)

Example 3 with DecimalMaxValidatorForNumber

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

the class MaxValidatorForStringTest method testInitializeDecimalMaxWithInvalidValue.

@Test
public void testInitializeDecimalMaxWithInvalidValue() {
    ConstraintAnnotationDescriptor.Builder<DecimalMax> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(DecimalMax.class);
    descriptorBuilder.setAttribute("value", "foobar");
    descriptorBuilder.setMessage("{validator.max}");
    DecimalMax m = descriptorBuilder.build().getAnnotation();
    DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber();
    try {
        constraint.initialize(m);
        fail();
    } catch (IllegalArgumentException e) {
    // success
    }
}
Also used : ConstraintAnnotationDescriptor(org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor) DecimalMaxValidatorForNumber(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForNumber) DecimalMax(jakarta.validation.constraints.DecimalMax) Test(org.testng.annotations.Test)

Example 4 with DecimalMaxValidatorForNumber

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

the class MaxValidatorForNumberTest method testIsValidDecimalMax1.

@Test
public void testIsValidDecimalMax1() {
    ConstraintAnnotationDescriptor.Builder<DecimalMax> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(DecimalMax.class);
    descriptorBuilder.setAttribute("value", Integer.toString(Integer.MAX_VALUE - 1));
    DecimalMax m = descriptorBuilder.build().getAnnotation();
    DecimalMaxValidatorForNumber constraint = new DecimalMaxValidatorForNumber();
    constraint.initialize(m);
    assertFalse(constraint.isValid(Double.POSITIVE_INFINITY, null));
}
Also used : ConstraintAnnotationDescriptor(org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor) DecimalMaxValidatorForNumber(org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForNumber) DecimalMax(jakarta.validation.constraints.DecimalMax) Test(org.testng.annotations.Test)

Aggregations

DecimalMaxValidatorForNumber (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForNumber)4 DecimalMax (jakarta.validation.constraints.DecimalMax)3 ConstraintAnnotationDescriptor (org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor)3 Test (org.testng.annotations.Test)3 AbstractDecimalMaxValidator (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.AbstractDecimalMaxValidator)1 DecimalMaxValidatorForBigDecimal (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigDecimal)1 DecimalMaxValidatorForBigInteger (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForBigInteger)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 DecimalMaxValidatorForInteger (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForInteger)1 DecimalMaxValidatorForLong (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForLong)1 DecimalMaxValidatorForShort (org.hibernate.validator.internal.constraintvalidators.bv.number.bound.decimal.DecimalMaxValidatorForShort)1