Skip to content

Commit

Permalink
Add tests for Measurement provider for el_GR locale
Browse files Browse the repository at this point in the history
  • Loading branch information
gvrettos committed Oct 27, 2024
1 parent f5a9312 commit d97f15c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class BaseFakerTest<T extends BaseFaker> {

private static final Logger LOG = Logger.getLogger(BaseFakerTest.class.getCanonicalName());
protected final T faker = getFaker();
protected T faker = getFaker();

@BeforeEach
@SuppressWarnings("EmptyTryBlock")
Expand All @@ -38,6 +38,10 @@ protected T getFaker() {
return (T) new BaseFaker();
}

protected void setFaker(T faker) {
this.faker = faker;
}

protected List<String> getBaseList(String key) {
return faker.fakeValuesService().fetchObject(key, faker.getContext());
}
Expand Down
35 changes: 33 additions & 2 deletions src/test/java/net/datafaker/providers/base/MeasurementTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package net.datafaker.providers.base;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested;

import java.util.List;
import java.util.Collection;
import java.util.Locale;

class MeasurementTest extends BaseFakerTest<BaseFaker> {

Expand All @@ -10,13 +15,39 @@ class MeasurementTest extends BaseFakerTest<BaseFaker> {
@Override
protected Collection<TestSpec> providerListTest() {
Measurement measurement = faker.measurement();
return List.of(TestSpec.of(measurement::height, "measurement.height"),
return getProviderListTests(measurement);
}

@Nested
class MeasurementInGreekTest extends BaseFakerTest<BaseFaker> {

@BeforeAll
void setup() {
this.setFaker(new BaseFaker(new Locale("el", "GR")));
}

@AfterAll
void reset() {
this.setFaker(this.getFaker());
}

@Override
protected Collection<TestSpec> providerListTest() {
Measurement measurement = faker.measurement();
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"));
TestSpec.of(measurement::metricWeight, "measurement.metric_weight")
);
}
}

0 comments on commit d97f15c

Please sign in to comment.