Please see below test. Current System is based on Spring-Boot 2.2.6.RELEASE which brings Hibernate-Validator 6.0.18 bundled.
```
import static org.assertj.core.api.Assertions.assertThat;
import java.math.BigDecimal;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class HibernateValidatorTest {
Validator validator;
@BeforeEach
public void setup() {
validator = Validation.buildDefaultValidatorFactory().getValidator();
}
public static class TestClass {
BigDecimal decimalMinValue;
BigDecimal minValue;
@DecimalMin("-1000.0")
public BigDecimal getDecimalMinValue() {
return decimalMinValue;
}
@Min(-1000)
public BigDecimal getMinValue() {
return minValue;
}
}
@Test
public void shouldWork() {
var testClass = new TestClass();
testClass.decimalMinValue = BigDecimal.ZERO;
testClass.minValue = BigDecimal.ZERO;
var violations = validator.validate(testClass);
assertThat(violations).isEmpty();
}
@Test
public void shouldWork_Minus1001() {
var testClass = new TestClass();
testClass.decimalMinValue = new BigDecimal("-1001");
testClass.minValue = new BigDecimal("-1001");
var violations = validator.validate(testClass);
assertThat(violations).hasSize(2);
}
@Test
public void shouldWork_DoubleMinValue() {
var testClass = new TestClass();
testClass.decimalMinValue = BigDecimal.valueOf(Double.MIN_VALUE);
testClass.minValue = BigDecimal.valueOf(Double.MIN_VALUE);
var violations = validator.validate(testClass);
assertThat(violations).hasSize(2); // no validation errors, has size 0!
}
}
```
Double.MIN_VALUE is not the lowest negative value that can be represented as a double, it's the lowest positive value that can be represented as a double. It's equal to 4.9e-324, which is higher than zero and higher than -1000. I think everything works as expected.
You probably meant to test -Double.MAX_VALUE.
doh… thanks a lot!
Thanks for confirming it was a misunderstanding. Closing!