|
1 | 1 | package it.aboutbits.springboot.testing.testdata.base; |
2 | 2 |
|
3 | 3 | import it.aboutbits.springboot.toolbox.type.identity.EntityId; |
| 4 | +import lombok.NonNull; |
4 | 5 | import net.datafaker.Faker; |
5 | 6 | import net.datafaker.service.FakeValuesService; |
6 | 7 | import net.datafaker.service.FakerContext; |
@@ -36,23 +37,27 @@ public FakerExtended(FakeValuesService fakeValuesService, FakerContext context) |
36 | 37 | super(fakeValuesService, context); |
37 | 38 | } |
38 | 39 |
|
39 | | - public <T extends Enum<?>> T randomEnumValue(Class<T> enumClass) { |
| 40 | + public <T extends Enum<?>> T randomEnumValue(@NonNull Class<T> enumClass) { |
40 | 41 | var values = enumClass.getEnumConstants(); |
41 | 42 | if (values.length == 0) { |
42 | 43 | throw new IllegalArgumentException("Enum class must have at least one value"); |
43 | 44 | } |
44 | 45 | return values[this.random().nextInt(values.length)]; |
45 | 46 | } |
46 | 47 |
|
47 | | - public <T extends EntityId<Long>> T randomEntityId(LongFunction<T> constructor) { |
| 48 | + public <T extends EntityId<Long>> T randomEntityId(@NonNull LongFunction<T> constructor) { |
48 | 49 | return constructor.apply( |
49 | | - super.random().nextInt(99999) |
| 50 | + super.random().nextInt(9999999) |
50 | 51 | ); |
51 | 52 | } |
52 | 53 |
|
53 | | - public <T extends EntityId<String>> T randomEntityId(Function<String, T> constructor) { |
| 54 | + public <T extends EntityId<String>> T randomEntityId(@NonNull Function<String, T> constructor) { |
54 | 55 | return constructor.apply( |
55 | 56 | super.internet().uuid() |
56 | 57 | ); |
57 | 58 | } |
| 59 | + |
| 60 | + public String unique(@NonNull String value) { |
| 61 | + return value + "_" + super.random().nextInt(9999999); |
| 62 | + } |
58 | 63 | } |
0 commit comments