Skip to content
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

add helper to generate entity ids #11

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.6</version>
<version>3.3.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package it.aboutbits.springboot.testing.testdata.base;

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 java.util.Locale;
import java.util.Random;
import java.util.function.LongFunction;

public class FakerExtended extends Faker {
public FakerExtended() {
Expand Down Expand Up @@ -40,4 +42,10 @@ public <T extends Enum<?>> T randomEnumValue(Class<T> enumClass) {
}
return values[this.random().nextInt(values.length)];
}

public <T extends EntityId<Long>> T randomEntityId(LongFunction<T> constructor) {
return constructor.apply(
super.random().nextInt(99999)
);
}
}