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
13 changes: 6 additions & 7 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions 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.4</version>
<version>3.3.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -24,7 +24,7 @@
<dependency>
<groupId>it.aboutbits</groupId>
<artifactId>spring-boot-toolbox</artifactId>
<version>1.0.0-RC4</version>
<version>1.0.0-RC6</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down Expand Up @@ -52,6 +52,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>net.datafaker</groupId>
<artifactId>datafaker</artifactId>
<version>2.4.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package it.aboutbits.springboot.testing.testdata.base;

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;

public class FakerExtended extends Faker {
public FakerExtended() {
super();
}

public FakerExtended(Locale locale) {
super(locale);
}

public FakerExtended(Random random) {
super(random);
}

public FakerExtended(Locale locale, Random random) {
super(locale, random);
}

public FakerExtended(Locale locale, RandomService randomService) {
super(locale, randomService);
}

public FakerExtended(FakeValuesService fakeValuesService, FakerContext context) {
super(fakeValuesService, context);
}

public <T extends Enum<?>> T randomEnumValue(Class<T> enumClass) {
var values = enumClass.getEnumConstants();
if (values.length == 0) {
throw new IllegalArgumentException("Enum class must have at least one value");
}
return values[this.random().nextInt(values.length)];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@SuppressWarnings("unchecked")
@Slf4j
public abstract class ModifyableTestDataCreator<CREATOR extends ModifyableTestDataCreator<CREATOR, ITEM, PARAMETER>, ITEM, PARAMETER> extends TestDataCreator<ITEM> {
protected static final FakerExtended FAKER = new FakerExtended();

private boolean mutatorSet = false;
private boolean mutatorCalled = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.function.Function;

public abstract class TestDataCreator<ITEM> {
protected static final FakerExtended FAKER = new FakerExtended();

protected final int numberOfItems;

protected TestDataCreator(int numberIfItems) {
Expand Down