Skip to content

Commit

Permalink
Merge pull request #194 from Tahanima/feature/add-measurement-faker
Browse files Browse the repository at this point in the history
Added Measurement Faker
  • Loading branch information
bodiam authored May 30, 2022
2 parents 380d21f + da89e97 commit 474401f
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ Providers
* Marketing
* Matz
* MBTI
* Measurement
* Medical
* Military
* Minecraft
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/datafaker/Faker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/net/datafaker/Measurement.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/datafaker/service/files/EnFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public String getPath() {
// "markdown.yml",
"marketing.yml",
"matz.yml",
// "measurement.yml",
"measurement.yml",
"mbti.yml",
"medical.yml",
"michael_scott.yml",
Expand Down
File renamed without changes.
50 changes: 50 additions & 0 deletions src/test/java/net/datafaker/MeasurementTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/test/java/net/datafaker/integration/FakerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 474401f

Please sign in to comment.