Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.aboutbits.springboot.testing.testdata.base;

import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal;
import it.aboutbits.springboot.toolbox.type.identity.EntityId;
import lombok.NonNull;
import net.datafaker.Faker;
Expand Down Expand Up @@ -60,4 +61,52 @@ public <T extends EntityId<String>> T randomEntityId(@NonNull Function<String, T
public String unique(@NonNull String value) {
return value + "_" + super.random().nextInt(9999999);
}

public RandomNumericRange numericRange() {
return new RandomNumericRange(
super.getFaker()
);
}

public static final class RandomNumericRange {
private final Faker parent;

private RandomNumericRange(Faker parent) {
this.parent = parent;
}

public NumericRange random() {
return random(-999999999, 999999999);
}

public NumericRange positive() {
return random(1, 999999999);
}

public NumericRange positiveOrZero() {
return random(0, 999999999);
}

public NumericRange negative() {
return random(-999999999, -1);
}

public NumericRange negativeOrZero() {
return random(-999999999, 0);
}

public NumericRange random(double min, double max) {
var lower = parent.random().nextDouble(min, max - 1);
var upper = parent.random().nextDouble(lower, max);

return new NumericRange(
ScaledBigDecimal.valueOf(lower),
ScaledBigDecimal.valueOf(upper)
);
}

public record NumericRange(ScaledBigDecimal lower, ScaledBigDecimal upper) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import jakarta.validation.groups.Default;
import lombok.NonNull;
import lombok.SneakyThrows;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -127,7 +128,7 @@ private static <P> void assertThatValidationIsCompliantForEachProperty(
} else {

// Use Bean Validation to validate the copy
var violations = validator.validate(copy);
var violations = validator.validate(copy, Default.class);

// Check if there are any violations
var violatingFieldMessages = violations
Expand Down