From da89e97c1bab3c0423156d87742643ad05ec93d3 Mon Sep 17 00:00:00 2001 From: Tahanima Chowdhury Date: Mon, 30 May 2022 19:23:35 +0600 Subject: [PATCH] Added Measurement Faker --- README.md | 1 + src/main/java/net/datafaker/Faker.java | 4 + src/main/java/net/datafaker/Measurement.java | 82 +++++++++++++++++++ .../net/datafaker/service/files/EnFile.java | 2 +- .../{measurement.todo.yml => measurement.yml} | 0 .../java/net/datafaker/MeasurementTest.java | 50 +++++++++++ .../net/datafaker/integration/FakerIT.java | 1 + 7 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/datafaker/Measurement.java rename src/main/resources/en/{measurement.todo.yml => measurement.yml} (100%) create mode 100644 src/test/java/net/datafaker/MeasurementTest.java diff --git a/README.md b/README.md index 98426bed4..e49cec59e 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,7 @@ Providers * Marketing * Matz * MBTI +* Measurement * Medical * Military * Minecraft diff --git a/src/main/java/net/datafaker/Faker.java b/src/main/java/net/datafaker/Faker.java index 74246ab44..57da3323b 100644 --- a/src/main/java/net/datafaker/Faker.java +++ b/src/main/java/net/datafaker/Faker.java @@ -660,6 +660,10 @@ public Matz matz() { public Mbti mbti() {return getProvider(Mbti.class, () -> new Mbti(this));} + public Measurement measurement() { + return getProvider(Measurement.class, () -> new Measurement(this)); + } + public Medical medical() { return getProvider(Medical.class, () -> new Medical(this)); } diff --git a/src/main/java/net/datafaker/Measurement.java b/src/main/java/net/datafaker/Measurement.java new file mode 100644 index 000000000..a5e84bebd --- /dev/null +++ b/src/main/java/net/datafaker/Measurement.java @@ -0,0 +1,82 @@ +package net.datafaker; + +public class Measurement { + + private final Faker faker; + + protected Measurement(Faker faker) { + this.faker = faker; + } + + /** + * This method generates a random height measurement. + * + * @return a string of height measurement. + */ + public String height() { + return faker.fakeValuesService().resolve("measurement.height", this, faker); + } + + /** + * This method generates a random length measurement. + * + * @return a string of length measurement. + */ + public String length() { + return faker.fakeValuesService().resolve("measurement.length", this, faker); + } + + /** + * This method generates a random volume measurement. + * + * @return a string of volume measurement. + */ + public String volume() { + return faker.fakeValuesService().resolve("measurement.volume", this, faker); + } + + /** + * This method generates a random weight measurement. + * + * @return a string of weight measurement. + */ + public String weight() { + return faker.fakeValuesService().resolve("measurement.weight", this, faker); + } + + /** + * This method generates a random metric height measurement. + * + * @return a string of metric height measurement. + */ + public String metricHeight() { + return faker.fakeValuesService().resolve("measurement.metric_height", this, faker); + } + + /** + * This method generates a random metric length measurement. + * + * @return a string of metric length measurement. + */ + public String metricLength() { + return faker.fakeValuesService().resolve("measurement.metric_length", this, faker); + } + + /** + * This method generates a random metric volume measurement. + * + * @return a string of metric volume measurement. + */ + public String metricVolume() { + return faker.fakeValuesService().resolve("measurement.metric_volume", this, faker); + } + + /** + * This method generates a random metric weight measurement. + * + * @return a string of metric weight measurement. + */ + public String metricWeight() { + return faker.fakeValuesService().resolve("measurement.metric_weight", this, faker); + } +} diff --git a/src/main/java/net/datafaker/service/files/EnFile.java b/src/main/java/net/datafaker/service/files/EnFile.java index ee32d3348..274fed1e6 100644 --- a/src/main/java/net/datafaker/service/files/EnFile.java +++ b/src/main/java/net/datafaker/service/files/EnFile.java @@ -132,7 +132,7 @@ public String getPath() { // "markdown.yml", "marketing.yml", "matz.yml", -// "measurement.yml", + "measurement.yml", "mbti.yml", "medical.yml", "michael_scott.yml", diff --git a/src/main/resources/en/measurement.todo.yml b/src/main/resources/en/measurement.yml similarity index 100% rename from src/main/resources/en/measurement.todo.yml rename to src/main/resources/en/measurement.yml diff --git a/src/test/java/net/datafaker/MeasurementTest.java b/src/test/java/net/datafaker/MeasurementTest.java new file mode 100644 index 000000000..e9a17700c --- /dev/null +++ b/src/test/java/net/datafaker/MeasurementTest.java @@ -0,0 +1,50 @@ +package net.datafaker; + +import org.junit.jupiter.api.RepeatedTest; + +import static org.assertj.core.api.Assertions.assertThat; + +class MeasurementTest extends AbstractFakerTest { + + public static final String WORDS = "^[a-z ]+$"; + + @RepeatedTest(10) + void testHeight() { + assertThat(faker.measurement().height()).matches(WORDS); + } + + @RepeatedTest(10) + void testLength() { + assertThat(faker.measurement().length()).matches(WORDS); + } + + @RepeatedTest(10) + void testVolume() { + assertThat(faker.measurement().volume()).matches(WORDS); + } + + @RepeatedTest(10) + void testWeight() { + assertThat(faker.measurement().weight()).matches(WORDS); + } + + @RepeatedTest(10) + void testMetricHeight() { + assertThat(faker.measurement().metricHeight()).matches(WORDS); + } + + @RepeatedTest(10) + void testMetricLength() { + assertThat(faker.measurement().metricLength()).matches(WORDS); + } + + @RepeatedTest(10) + void testMetricVolume() { + assertThat(faker.measurement().metricVolume()).matches(WORDS); + } + + @RepeatedTest(10) + void testMetricWeight() { + assertThat(faker.measurement().metricWeight()).matches(WORDS); + } +} diff --git a/src/test/java/net/datafaker/integration/FakerIT.java b/src/test/java/net/datafaker/integration/FakerIT.java index 6c0bb7e96..d566ff0eb 100644 --- a/src/test/java/net/datafaker/integration/FakerIT.java +++ b/src/test/java/net/datafaker/integration/FakerIT.java @@ -150,6 +150,7 @@ void testAllFakerMethodsThatReturnStrings(Locale locale, Random random) throws E testAllMethodsThatReturnStringsActuallyReturnStrings(faker.lorem()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.marketing()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.matz()); + testAllMethodsThatReturnStringsActuallyReturnStrings(faker.measurement()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.military()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.mountain()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.mountaineering());