Skip to content

Commit

Permalink
add helper to generate entity ids
Browse files Browse the repository at this point in the history
  • Loading branch information
SirCotare committed Jan 22, 2025
1 parent f165ea4 commit 52cde3d
Showing 1 changed file with 8 additions and 0 deletions.
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)
);
}
}

0 comments on commit 52cde3d

Please sign in to comment.