Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -12,7 +12,7 @@
<packaging>jar</packaging>

<artifactId>testcontainers-annotations</artifactId>
<version>4.1.1</version>
<version>4.1.3</version>

<name>testcontainers-annotations</name>
<description>testcontainers-annotations</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,34 @@

public class RandomBeans {

public static final long DEFAULT_SEED = 123L;

public static <T> T random(Class<T> type, String... excludedFields) {
var parameters = createParametersWithExcludedFields(excludedFields);
var parameters = createParametersWithExcludedFields(DEFAULT_SEED, excludedFields);
var easyRandom = new EasyRandom(parameters);
return easyRandom.nextObject(type);
}

public static <T> T random(Long seed, Class<T> type, String... excludedFields) {
var parameters = createParametersWithExcludedFields(seed, excludedFields);
var easyRandom = new EasyRandom(parameters);
return easyRandom.nextObject(type);
}

public static <T> List<T> randomListOf(int amount, Class<T> type, String... excludedFields) {
var parameters = createParametersWithExcludedFields(excludedFields);
var parameters = createParametersWithExcludedFields(DEFAULT_SEED, excludedFields);
var easyRandom = new EasyRandom(parameters);
return easyRandom.objects(type, amount).collect(Collectors.toList());
}

public static <T> List<T> randomListOf(Long seed, int amount, Class<T> type, String... excludedFields) {
var parameters = createParametersWithExcludedFields(seed, excludedFields);
var easyRandom = new EasyRandom(parameters);
return easyRandom.objects(type, amount).collect(Collectors.toList());
}

public static <T> Stream<T> randomStreamOf(int amount, Class<T> type, String... excludedFields) {
var parameters = createParametersWithExcludedFields(excludedFields);
var parameters = createParametersWithExcludedFields(DEFAULT_SEED, excludedFields);
var easyRandom = new EasyRandom(parameters);
return easyRandom.objects(type, amount);
}
Expand All @@ -56,7 +70,7 @@ public static <T> Stream<T> randomStreamOf(int amount, Class<T> type, String...
return mockTBaseProcessor.process(type.getConstructor().newInstance(), new TBaseHandler<>(type));
}

private static EasyRandomParameters createParametersWithExcludedFields(String... excludedFields) {
private static EasyRandomParameters createParametersWithExcludedFields(Long seed, String... excludedFields) {
var parameters = new EasyRandomParameters();
parameters.randomize(LocalDateTime.class, () -> {
var dateTime = LocalDateTime.now();
Expand Down Expand Up @@ -98,7 +112,8 @@ private static EasyRandomParameters createParametersWithExcludedFields(String...
parameters.excludeField(field -> field.getName().equals(excludedField));
}
}
parameters.objectPoolSize(100)
parameters.seed(seed)
.objectPoolSize(100)
.randomizationDepth(3)
.charset(StandardCharsets.UTF_8)
.stringLengthRange(5, 50)
Expand Down