Search in sources :

Example 1 with NegativeValidatorForCharSequence

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

the class NegativePositiveValidatorForStringTest method testIsValidNegativeValidator.

@Test
public void testIsValidNegativeValidator() {
    ConstraintAnnotationDescriptor.Builder<Negative> descriptorBuilder = new ConstraintAnnotationDescriptor.Builder<>(Negative.class);
    descriptorBuilder.setMessage("{validator.negative}");
    Negative m = descriptorBuilder.build().getAnnotation();
    NegativeValidatorForCharSequence constraint = new NegativeValidatorForCharSequence();
    constraint.initialize(m);
    assertTrue(constraint.isValid(null, null));
    assertFalse(constraint.isValid("15", null));
    assertFalse(constraint.isValid("15.0", null));
    assertFalse(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 : NegativeValidatorForCharSequence(org.hibernate.validator.internal.constraintvalidators.bv.number.sign.NegativeValidatorForCharSequence) ConstraintAnnotationDescriptor(org.hibernate.validator.internal.util.annotation.ConstraintAnnotationDescriptor) Negative(jakarta.validation.constraints.Negative) Test(org.testng.annotations.Test)

Aggregations

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