Search in sources :

Example 1 with NegativeOrZeroValidatorForCharSequence

use of org.hibernate.validator.internal.constraintvalidators.bv.number.sign.NegativeOrZeroValidatorForCharSequence in project hibernate-validator by hibernate.

the class NegativePositiveValidatorForStringTest method testIsValidNegativeOrZeroValidator.

@Test
public void testIsValidNegativeOrZeroValidator() {
    ConstraintAnnotationDescriptor.Builder<NegativeOrZero> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(NegativeOrZero.class);
    descriptorBuilder.setMessage("{validator.negativeOrZero}");
    NegativeOrZero m = descriptorBuilder.build().getAnnotation();
    NegativeOrZeroValidatorForCharSequence constraint = new NegativeOrZeroValidatorForCharSequence();
    constraint.initialize(m);
    assertTrue(constraint.isValid(null, null));
    assertFalse(constraint.isValid("15", null));
    assertFalse(constraint.isValid("15.0", null));
    assertTrue(constraint.isValid("0", null));
    assertTrue(constraint.isValid("-10", null));
    assertTrue(constraint.isValid("-14.99", null));
    // number format exception
    assertFalse(constraint.isValid("15l", null));
}
Also used : NegativeOrZeroValidatorForCharSequence(org.hibernate.validator.internal.constraintvalidators.bv.number.sign.NegativeOrZeroValidatorForCharSequence) ConstraintAnnotationDescriptor(org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor) NegativeOrZero(jakarta.validation.constraints.NegativeOrZero) Test(org.testng.annotations.Test)

Aggregations

NegativeOrZero (jakarta.validation.constraints.NegativeOrZero)1 NegativeOrZeroValidatorForCharSequence (org.hibernate.validator.internal.constraintvalidators.bv.number.sign.NegativeOrZeroValidatorForCharSequence)1 ConstraintAnnotationDescriptor (org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor)1 Test (org.testng.annotations.Test)1