Skip to content

Commit 52cde3d

Browse files
committed
add helper to generate entity ids
1 parent f165ea4 commit 52cde3d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/main/java/it/aboutbits/springboot/testing/testdata/base/FakerExtended.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package it.aboutbits.springboot.testing.testdata.base;
22

3+
import it.aboutbits.springboot.toolbox.type.identity.EntityId;
34
import net.datafaker.Faker;
45
import net.datafaker.service.FakeValuesService;
56
import net.datafaker.service.FakerContext;
67
import net.datafaker.service.RandomService;
78

89
import java.util.Locale;
910
import java.util.Random;
11+
import java.util.function.LongFunction;
1012

1113
public class FakerExtended extends Faker {
1214
public FakerExtended() {
@@ -40,4 +42,10 @@ public <T extends Enum<?>> T randomEnumValue(Class<T> enumClass) {
4042
}
4143
return values[this.random().nextInt(values.length)];
4244
}
45+
46+
public <T extends EntityId<Long>> T randomEntityId(LongFunction<T> constructor) {
47+
return constructor.apply(
48+
super.random().nextInt(99999)
49+
);
50+
}
4351
}

0 commit comments

Comments
 (0)