Skip to content

Commit

Permalink
Move utility method for tests on top of the actual tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gvrettos committed Oct 27, 2024
1 parent 79e2821 commit 054a8b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions src/test/java/net/datafaker/providers/base/AncientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

class AncientTest extends BaseFakerTest<BaseFaker> {

private static Collection<TestSpec> getProviderListTests(Ancient ancient) {
return List.of(
TestSpec.of(ancient::god, "ancient.god"),
TestSpec.of(ancient::primordial, "ancient.primordial"),
TestSpec.of(ancient::titan, "ancient.titan"),
TestSpec.of(ancient::hero, "ancient.hero")
);
}

@Override
protected Collection<TestSpec> providerListTest() {
Ancient ancient = faker.ancient();
Expand All @@ -35,13 +44,4 @@ protected Collection<TestSpec> providerListTest() {
return getProviderListTests(ancient);
}
}

private Collection<TestSpec> getProviderListTests(Ancient ancient) {
return List.of(
TestSpec.of(ancient::god, "ancient.god"),
TestSpec.of(ancient::primordial, "ancient.primordial"),
TestSpec.of(ancient::titan, "ancient.titan"),
TestSpec.of(ancient::hero, "ancient.hero")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ void testQuote() {
assertThat(faker.greekPhilosopher().quote()).matches("^[a-zA-Z ,.']+$");
}

private static Collection<TestSpec> getProviderListTests(GreekPhilosopher greekPhilosopher) {
return List.of(
TestSpec.of(greekPhilosopher::name, "greek_philosophers.names"),
TestSpec.of(greekPhilosopher::quote, "greek_philosophers.quotes")
);
}

@Override
protected Collection<TestSpec> providerListTest() {
GreekPhilosopher greekPhilosopher = faker.greekPhilosopher();
Expand All @@ -48,11 +55,4 @@ protected Collection<TestSpec> providerListTest() {
return getProviderListTests(greekPhilosopher);
}
}

private Collection<TestSpec> getProviderListTests(GreekPhilosopher greekPhilosopher) {
return List.of(
TestSpec.of(greekPhilosopher::name, "greek_philosophers.names"),
TestSpec.of(greekPhilosopher::quote, "greek_philosophers.quotes")
);
}
}
26 changes: 13 additions & 13 deletions src/test/java/net/datafaker/providers/base/MeasurementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ class MeasurementTest extends BaseFakerTest<BaseFaker> {

public static final String WORDS = "^[a-z ]+$";

private static Collection<TestSpec> getProviderListTests(Measurement measurement) {
return List.of(
TestSpec.of(measurement::height, "measurement.height"),
TestSpec.of(measurement::length, "measurement.length"),
TestSpec.of(measurement::volume, "measurement.volume"),
TestSpec.of(measurement::weight, "measurement.weight"),
TestSpec.of(measurement::metricLength, "measurement.metric_length"),
TestSpec.of(measurement::metricHeight, "measurement.metric_height"),
TestSpec.of(measurement::metricVolume, "measurement.metric_volume"),
TestSpec.of(measurement::metricWeight, "measurement.metric_weight")
);
}

@Override
protected Collection<TestSpec> providerListTest() {
Measurement measurement = faker.measurement();
Expand All @@ -37,17 +50,4 @@ protected Collection<TestSpec> providerListTest() {
return getProviderListTests(measurement);
}
}

private Collection<TestSpec> getProviderListTests(Measurement measurement) {
return List.of(
TestSpec.of(measurement::height, "measurement.height"),
TestSpec.of(measurement::length, "measurement.length"),
TestSpec.of(measurement::volume, "measurement.volume"),
TestSpec.of(measurement::weight, "measurement.weight"),
TestSpec.of(measurement::metricLength, "measurement.metric_length"),
TestSpec.of(measurement::metricHeight, "measurement.metric_height"),
TestSpec.of(measurement::metricVolume, "measurement.metric_volume"),
TestSpec.of(measurement::metricWeight, "measurement.metric_weight")
);
}
}

0 comments on commit 054a8b7

Please sign in to comment.