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

This file was deleted.

31 changes: 9 additions & 22 deletions src/test/java/net/datafaker/providers/base/AncientTest.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
package net.datafaker.providers.base;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.Collection;

class AncientTest extends BaseFakerTest<BaseFaker> {

@Test
void god() {
assertThat(faker.ancient().god()).matches("\\w+");
}

@Test
void primordial() {
assertThat(faker.ancient().primordial()).matches("\\w+");
}

@Test
void titan() {
assertThat(faker.ancient().titan()).matches("\\w+");
}

@Test
void hero() {
assertThat(faker.ancient().hero()).matches("(?U)\\w+");
@Override
protected Collection<TestSpec> providerListTest() {
Ancient ancient = faker.ancient();
return Arrays.asList(TestSpec.of(ancient::god, "ancient.god"),
TestSpec.of(ancient::primordial, "ancient.primordial"),
TestSpec.of(ancient::titan, "ancient.titan"),
TestSpec.of(ancient::hero, "ancient.hero"));
}

}
19 changes: 11 additions & 8 deletions src/test/java/net/datafaker/providers/base/AnimalTest.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
package net.datafaker.providers.base;

import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.Collection;

class AnimalTest extends BaseFakerTest<BaseFaker> {

@Test
void name() {
assertThat(faker.animal().name()).matches("[A-Za-z ]+");
private Animal animal = faker.animal();

@Override
protected Collection<TestSpec> providerListTest() {
return Arrays.asList(TestSpec.of(animal::name, "creature.animal.name"));
}

@RepeatedTest(100)
void scientificName() {
assertThat(faker.animal().scientificName()).matches("[A-Z][a-z]+ [a-z]+");
assertThat(animal.scientificName()).matches("[A-Z][a-z]+ [a-z]+");
}

@RepeatedTest(100)
void genus() {
assertThat(faker.animal().genus()).matches("[A-Z][a-z]+");
assertThat(animal.genus()).matches("[A-Z][a-z]+");
}

@RepeatedTest(100)
void species() {
assertThat(faker.animal().species()).matches("[a-z]+");
assertThat(animal.species()).matches("[a-z]+");
}
}
17 changes: 11 additions & 6 deletions src/test/java/net/datafaker/providers/base/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.Collection;

class AppTest extends BaseFakerTest<BaseFaker> {

@Test
void testName() {
assertThat(faker.app().name()).matches("([\\w-]+ ?)+");
}
private App app = faker.app();

@Test
void testVersion() {
assertThat(faker.app().version()).matches("\\d\\.(\\d){1,2}(\\.\\d)?");
assertThat(app.version()).matches("\\d\\.(\\d){1,2}(\\.\\d)?");
}

@Test
void testAuthor() {
assertThat(faker.app().author()).matches("([\\w']+[-&,.]? ?){2,9}");
assertThat(app.author()).matches("([\\w']+[-&,.]? ?){2,9}");
}

@Override
protected Collection<TestSpec> providerListTest() {
return Arrays.asList(TestSpec.of(app::name, "app.name", "([\\w-]+ ?)+"));
}
}
15 changes: 4 additions & 11 deletions src/test/java/net/datafaker/providers/base/ApplianceTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package net.datafaker.providers.base;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.Collection;

class ApplianceTest extends AbstractBasicProviderTest<BaseFaker> {

@Test
void brand() {
assertThat(faker.appliance().brand()).matches("[A-Za-z .-]+");
}
class ApplianceTest extends BaseFakerTest<BaseFaker> {

@Override
protected Collection<TestSpec> providerListTest() {
return Arrays.asList(TestSpec.of(() -> faker.appliance().equipment(), "appliance.equipment"));
Appliance appliance = faker.appliance();
return Arrays.asList(TestSpec.of(appliance::brand, "appliance.brand", "[A-Za-z .-]+"),
TestSpec.of(appliance::equipment, "appliance.equipment"));
}
}
12 changes: 6 additions & 6 deletions src/test/java/net/datafaker/providers/base/ArtistTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.datafaker.providers.base;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.Collection;

class ArtistTest extends BaseFakerTest<BaseFaker> {

@Test
void name() {
assertThat(faker.artist().name()).matches("(\\w+ ?){1,2}");
@Override
protected Collection<TestSpec> providerListTest() {
Artist artist = faker.artist();
return Arrays.asList(TestSpec.of(artist::name, "artist.names", "(\\w+ ?){1,2}"));
}
}
9 changes: 5 additions & 4 deletions src/test/java/net/datafaker/providers/base/AustraliaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import java.util.Arrays;
import java.util.Collection;

class AustraliaTest extends AbstractBasicProviderTest<BaseFaker> {
class AustraliaTest extends BaseFakerTest<BaseFaker> {

@Override
protected Collection<TestSpec> providerListTest() {
return Arrays.asList(TestSpec.of(() -> faker.australia().locations(), "australia.locations"),
TestSpec.of(() -> faker.australia().animals(), "australia.animals"),
TestSpec.of(() -> faker.australia().states(), "australia.states"));
Australia astralia = faker.australia();
return Arrays.asList(TestSpec.of(astralia::locations, "australia.locations"),
TestSpec.of(astralia::animals, "australia.animals"),
TestSpec.of(astralia::states, "australia.states"));
}

}
20 changes: 9 additions & 11 deletions src/test/java/net/datafaker/providers/base/AviationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,30 @@
import java.util.Arrays;
import java.util.Collection;

class AviationTest extends AbstractBasicProviderTest<BaseFaker> {
class AviationTest extends BaseFakerTest<BaseFaker> {

@Test
void airport() {
assertThat(faker.aviation().airport()).matches("\\w{4}");
}
private Aviation aviation = faker.aviation();

@Test
void flight_ICAO() {
assertThat(faker.aviation().flight("ICAO")).matches("[A-Z]{3}[0-9]+");
assertThat(aviation.flight("ICAO")).matches("[A-Z]{3}[0-9]+");
}

@Test
void flight_IATA() {
assertThat(faker.aviation().flight("IATA")).matches("[A-Z]{2}[0-9]+");
assertThat(aviation.flight("IATA")).matches("[A-Z]{2}[0-9]+");
}

@Test
void flight_default() {
assertThat(faker.aviation().flight()).matches("[A-Z]{2}[0-9]+");
assertThat(aviation.flight()).matches("[A-Z]{2}[0-9]+");
}

@Override
protected Collection<TestSpec> providerListTest() {
return Arrays.asList(TestSpec.of(() -> faker.aviation().aircraft(), "aviation.aircraft"),
TestSpec.of(() -> faker.aviation().METAR(), "aviation.metar"),
TestSpec.of(() -> faker.aviation().airline(), "aviation.airline"));
return Arrays.asList(TestSpec.of(aviation::airport, "aviation.airport", "\\w{4}"),
TestSpec.of(aviation::aircraft, "aviation.aircraft"),
TestSpec.of(aviation::METAR, "aviation.metar"),
TestSpec.of(aviation::airline, "aviation.airline"));
}
}
19 changes: 16 additions & 3 deletions src/test/java/net/datafaker/providers/base/BaseFakerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -25,6 +26,7 @@ public class BaseFakerTest<T extends BaseFaker> {
protected final T faker = getFaker();

@BeforeEach
@SuppressWarnings("unchecked")
protected void before() {
try (AutoCloseable ignored = MockitoAnnotations.openMocks(this)) {

Expand All @@ -39,6 +41,7 @@ protected void before() {
}
}

@SuppressWarnings("unchecked")
protected T getFaker() {
return (T) new BaseFaker();
}
Expand Down Expand Up @@ -68,26 +71,36 @@ protected void testProviderList(TestSpec testSpec, TestInfo testInfo) {
assertThat(item).as("Check item isn't empty").isNotEmpty();
assertThat(actual).as("Check actual list isn't empty and contains the item for the key \"" + testSpec.key + "\"").isNotEmpty()
.anyMatch(item::equals);
if (!testSpec.regex.isEmpty()) {
assertThat(item).as("Check item matches regex").matches(Pattern.compile(testSpec.regex));
}
}

protected Collection<TestSpec> providerListTest() {
// dummy test since parameterized test requires non-empty collection
return Collections.singleton(new TestSpec(null, null));
return Collections.singleton(new TestSpec(null, null, null));
}

protected static class TestSpec {
private final Supplier<?> supplier;
private final String key;
private final boolean isDummy;
@SuppressWarnings("unused")
private final String regex;

private TestSpec(Supplier<?> supplier, String key) {
private TestSpec(Supplier<?> supplier, String key, String regex) {
this.supplier = supplier;
this.key = key;
this.isDummy = key == null || supplier == null;
this.regex = regex;
}

public static TestSpec of(Supplier<?> supplier, String key) {
return new TestSpec(supplier, key);
return new TestSpec(supplier, key, "");
}

public static TestSpec of(Supplier<?> supplier, String key, String regex) {
return new TestSpec(supplier, key, regex);
}

@Override
Expand Down
31 changes: 9 additions & 22 deletions src/test/java/net/datafaker/providers/base/BloodTypeTest.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
package net.datafaker.providers.base;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.Collection;

class BloodTypeTest extends BaseFakerTest<BaseFaker> {

@Test
void aboTypes() {
assertThat(faker.bloodtype().aboTypes()).matches("[A-Za-z]+");
}

@Test
void rhTypes() {
assertThat(faker.bloodtype().rhTypes()).matches("[A-Za-z+-]+");
}

@Test
void pTypes() {
assertThat(faker.bloodtype().pTypes()).matches("[A-Za-z\\d]+");
}

@Test
void testBloodGroup() {
assertThat(faker.bloodtype().bloodGroup()).matches("(A|B|AB|O)[+-]");
@Override
protected Collection<TestSpec> providerListTest() {
BloodType bloodType = faker.bloodtype();
return Arrays.asList(TestSpec.of(bloodType::aboTypes, "blood_type.abo_types", "[A-Za-z]+"),
TestSpec.of(bloodType::rhTypes, "blood_type.rh_types", "[A-Za-z+-]+"),
TestSpec.of(bloodType::pTypes, "blood_type.p_types", "[A-Za-z\\d]+"),
TestSpec.of(bloodType::bloodGroup, "blood_type.blood_group", "(A|B|AB|O)[+-]"));
}

}
23 changes: 10 additions & 13 deletions src/test/java/net/datafaker/providers/base/BookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.Collection;

class BookTest extends BaseFakerTest<BaseFaker> {

@Test
void testTitle() {
assertThat(faker.book().title()).matches("([\\p{L}'\\-?]+[!,]? ?){2,9}");
}
private Book book = faker.book();

@Test
void testAuthor() {
assertThat(faker.book().author()).matches("([\\w']+\\.? ?){2,3}");
assertThat(book.author()).matches("([\\w']+\\.? ?){2,3}");
}

@Test
void testPublisher() {
assertThat(faker.book().publisher()).matches("([\\p{L}'&\\-]+[,.]? ?){1,5}");
}

@Test
void testGenre() {
assertThat(faker.book().genre()).matches("([\\w/]+ ?){2,4}");
@Override
protected Collection<TestSpec> providerListTest() {
return Arrays.asList(TestSpec.of(() -> faker.book().title(), "book.title", "([\\p{L}'\\-?]+[!,]? ?){2,9}"),
TestSpec.of(() -> faker.book().publisher(), "book.publisher", "([\\p{L}'&\\-]+[,.]? ?){1,5}"),
TestSpec.of(() -> faker.book().genre(), "book.genre", "([\\w/]+ ?){2,4}"));
}
}
9 changes: 5 additions & 4 deletions src/test/java/net/datafaker/providers/base/BrandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import java.util.Arrays;
import java.util.Collection;

class BrandTest extends AbstractBasicProviderTest<BaseFaker> {
class BrandTest extends BaseFakerTest<BaseFaker> {

@Override
protected Collection<TestSpec> providerListTest() {
Brand brand = faker.brand();
return Arrays.asList(
TestSpec.of(() -> faker.brand().sport(), "brand.sport"),
TestSpec.of(() -> faker.brand().car(), "vehicle.makes"),
TestSpec.of(() -> faker.brand().watch(), "brand.watch")
TestSpec.of(brand::sport, "brand.sport"),
TestSpec.of(brand::car, "vehicle.makes"),
TestSpec.of(brand::watch, "brand.watch")
);
}
}
Loading