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