-
Notifications
You must be signed in to change notification settings - Fork 113
Description
Describe the bug
When trying to generate test values using FixtureMonkey, an IllegalArgumentException is thrown if the minimum and maximum values are equal and the borders are not included (from jqwik). This issue affects BigDecimal and floating-point types (float, double) when using similar validation constraints.
Your environment
- version of Fixture Monkey: 1.1.5
- version of Java: 17
Steps to reproduce
- Create a test using FixtureMonkey where BigDecimal or floating-point (float, double) values are generated
- Set minimum and maximum values to be equal (e.g., 2.0)
- The borders are not included in the range
class TEST {
private Validator validator;
@BeforeEach
void setUp() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
}
@Test
void success() {
A object = new A(new BigDecimal("2"));
Set<ConstraintViolation<A>> violations = validator.validate(object);
assertThat(violations).isEmpty(); // [SUCCESS]
}
@Test
void fail() {
FixtureMonkey sut = FixtureMonkey.builder()
.plugin(new JakartaValidationPlugin())
.build();
sut.giveMeOne(A.class); // [ERROR] If min value [2.0] is equal to max value [2.0] borders must be included.
}
public static class A {
public A() {}
public A(BigDecimal value) {
this.value = value;
}
@NotNull
// The same exception occurs with:
// - @Min @Max annotations
// - float/double types with similar constraints
@DecimalMax(value = "2.0")
@DecimalMin(value = "2.0")
private BigDecimal value;
public BigDecimal getValue() {
return value;
}
public void setValue( BigDecimal value) {
this.value = value;
}
}
}
If min value [2.0] is equal to max value [2.0] borders must be included.
java.lang.IllegalArgumentException: If min value [2.0] is equal to max value [2.0] borders must be included.
at net.jqwik.engine.properties.Range.of(Range.java:18)
at net.jqwik.engine.properties.arbitraries.DefaultBigDecimalArbitrary.between(DefaultBigDecimalArbitrary.java:57)
at net.jqwik.engine.properties.arbitraries.DefaultBigDecimalArbitrary.lessOrEqual(DefaultBigDecimalArbitrary.java:68)
at com.navercorp.fixturemonkey.api.jqwik.JqwikJavaArbitraryResolver.bigDecimals(JqwikJavaArbitraryResolver.java:476)
Expected behaviour
When minimum and maximum values are equal (e.g., 2.0), the test data should be generated successfully.
The generated test data should match the actual validation behavior
This will ensure consistent behavior between test data generation and actual validation logic.
Actual behaviour
The system throws an IllegalArgumentException during test data generation, preventing the creation of test cases with equal minimum and maximum values. This causes a mismatch between test data generation and actual validation behavior.
If this exception is not intended behavior, please let me know if I can submit a PR for the fix!
The root cause appears to be the incorrect handling of the inclusive property internally.
Although I can identify the likely source of the issue, I would appreciate any tips for running integration tests after the fix. In particular, I'd like to make sure the fix doesn't cause any unexpected behavior in other scenarios.