-
Notifications
You must be signed in to change notification settings - Fork 0
update & fixes #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
update & fixes #33
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ff97566
update versions
SirCotare 4890577
add validation tools for new toolbox
SirCotare e172aca
Merge branch 'main' into toolbox-update-validations
SirCotare 2116a2e
remove redundant faker instance already present in superclass. preven…
SirCotare 09ea93b
move faker
SirCotare cd4ac55
fix nullability
SirCotare 1e8d4bc
update versions
SirCotare 113872f
update versions
SirCotare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/main/java/it/aboutbits/springboot/testing/testdata/FakerExtended.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package it.aboutbits.springboot.testing.testdata; | ||
|
|
||
| import it.aboutbits.springboot.toolbox.type.ScaledBigDecimal; | ||
| import it.aboutbits.springboot.toolbox.type.identity.EntityId; | ||
| import net.datafaker.Faker; | ||
| import net.datafaker.service.FakeValuesService; | ||
| import net.datafaker.service.FakerContext; | ||
| import net.datafaker.service.RandomService; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| import java.util.Locale; | ||
| import java.util.Random; | ||
| import java.util.function.Function; | ||
| import java.util.function.LongFunction; | ||
|
|
||
| @NullMarked | ||
| public class FakerExtended extends Faker { | ||
| public FakerExtended() { | ||
| super(); | ||
| } | ||
|
|
||
| public FakerExtended(Locale locale) { | ||
| super(locale); | ||
| } | ||
|
|
||
| public FakerExtended(Random random) { | ||
| super(random); | ||
| } | ||
|
|
||
| public FakerExtended(Locale locale, Random random) { | ||
| super(locale, random); | ||
| } | ||
|
|
||
| public FakerExtended(Locale locale, RandomService randomService) { | ||
| super(locale, randomService); | ||
| } | ||
|
|
||
| public FakerExtended(FakeValuesService fakeValuesService, FakerContext context) { | ||
| super(fakeValuesService, context); | ||
| } | ||
|
|
||
| public <T extends Enum<?>> T randomEnumValue(Class<T> enumClass) { | ||
| var values = enumClass.getEnumConstants(); | ||
| if (values.length == 0) { | ||
| throw new IllegalArgumentException("Enum class must have at least one value"); | ||
| } | ||
| return values[this.random().nextInt(values.length)]; | ||
| } | ||
|
|
||
| public <T extends EntityId<Long>> T randomEntityId(LongFunction<T> constructor) { | ||
| return constructor.apply( | ||
| super.random().nextInt(9999999) | ||
| ); | ||
| } | ||
|
|
||
| public <T extends EntityId<String>> T randomEntityId(Function<String, T> constructor) { | ||
| return constructor.apply( | ||
| super.internet().uuid() | ||
| ); | ||
| } | ||
|
|
||
| public String unique(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) { | ||
|
|
||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/java/it/aboutbits/springboot/testing/testdata/base/TestDataCreator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/it/aboutbits/springboot/testing/validation/core/ValueSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| package it.aboutbits.springboot.testing.validation.core; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.util.stream.Stream; | ||
|
|
||
| @NullMarked | ||
| public interface ValueSource { | ||
| <T> Stream<T> values(Class<T> propertyClass, Object... args); | ||
| <T> Stream<@Nullable T> values(Class<T> propertyClass, Object... args); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.