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));
}
Aggregations