use of jakarta.validation.constraints.Negative in project jsonschema-generator by victools.
the class JakartaValidationModule method resolveNumberExclusiveMaximum.
/**
* Determine a number type's maximum (exclusive) value.
*
* @param member the field or method to check
* @return specified exclusive maximum value (or null)
* @see DecimalMax#inclusive()
* @see Negative
*/
protected BigDecimal resolveNumberExclusiveMaximum(MemberScope<?, ?> member) {
DecimalMax decimalMaxAnnotation = this.getAnnotationFromFieldOrGetter(member, DecimalMax.class, DecimalMax::groups);
if (decimalMaxAnnotation != null && !decimalMaxAnnotation.inclusive()) {
return new BigDecimal(decimalMaxAnnotation.value());
}
Negative negativeAnnotation = this.getAnnotationFromFieldOrGetter(member, Negative.class, Negative::groups);
if (negativeAnnotation != null) {
return BigDecimal.ZERO;
}
return null;
}
use of jakarta.validation.constraints.Negative 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