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