Skip to content

Commit 474401f

Browse files
authored
Merge pull request #194 from Tahanima/feature/add-measurement-faker
Added Measurement Faker
2 parents 380d21f + da89e97 commit 474401f

File tree

7 files changed

+139
-1
lines changed

7 files changed

+139
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ Providers
242242
* Marketing
243243
* Matz
244244
* MBTI
245+
* Measurement
245246
* Medical
246247
* Military
247248
* Minecraft

src/main/java/net/datafaker/Faker.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,10 @@ public Matz matz() {
660660

661661
public Mbti mbti() {return getProvider(Mbti.class, () -> new Mbti(this));}
662662

663+
public Measurement measurement() {
664+
return getProvider(Measurement.class, () -> new Measurement(this));
665+
}
666+
663667
public Medical medical() {
664668
return getProvider(Medical.class, () -> new Medical(this));
665669
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package net.datafaker;
2+
3+
public class Measurement {
4+
5+
private final Faker faker;
6+
7+
protected Measurement(Faker faker) {
8+
this.faker = faker;
9+
}
10+
11+
/**
12+
* This method generates a random height measurement.
13+
*
14+
* @return a string of height measurement.
15+
*/
16+
public String height() {
17+
return faker.fakeValuesService().resolve("measurement.height", this, faker);
18+
}
19+
20+
/**
21+
* This method generates a random length measurement.
22+
*
23+
* @return a string of length measurement.
24+
*/
25+
public String length() {
26+
return faker.fakeValuesService().resolve("measurement.length", this, faker);
27+
}
28+
29+
/**
30+
* This method generates a random volume measurement.
31+
*
32+
* @return a string of volume measurement.
33+
*/
34+
public String volume() {
35+
return faker.fakeValuesService().resolve("measurement.volume", this, faker);
36+
}
37+
38+
/**
39+
* This method generates a random weight measurement.
40+
*
41+
* @return a string of weight measurement.
42+
*/
43+
public String weight() {
44+
return faker.fakeValuesService().resolve("measurement.weight", this, faker);
45+
}
46+
47+
/**
48+
* This method generates a random metric height measurement.
49+
*
50+
* @return a string of metric height measurement.
51+
*/
52+
public String metricHeight() {
53+
return faker.fakeValuesService().resolve("measurement.metric_height", this, faker);
54+
}
55+
56+
/**
57+
* This method generates a random metric length measurement.
58+
*
59+
* @return a string of metric length measurement.
60+
*/
61+
public String metricLength() {
62+
return faker.fakeValuesService().resolve("measurement.metric_length", this, faker);
63+
}
64+
65+
/**
66+
* This method generates a random metric volume measurement.
67+
*
68+
* @return a string of metric volume measurement.
69+
*/
70+
public String metricVolume() {
71+
return faker.fakeValuesService().resolve("measurement.metric_volume", this, faker);
72+
}
73+
74+
/**
75+
* This method generates a random metric weight measurement.
76+
*
77+
* @return a string of metric weight measurement.
78+
*/
79+
public String metricWeight() {
80+
return faker.fakeValuesService().resolve("measurement.metric_weight", this, faker);
81+
}
82+
}

src/main/java/net/datafaker/service/files/EnFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public String getPath() {
132132
// "markdown.yml",
133133
"marketing.yml",
134134
"matz.yml",
135-
// "measurement.yml",
135+
"measurement.yml",
136136
"mbti.yml",
137137
"medical.yml",
138138
"michael_scott.yml",
File renamed without changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package net.datafaker;
2+
3+
import org.junit.jupiter.api.RepeatedTest;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
class MeasurementTest extends AbstractFakerTest {
8+
9+
public static final String WORDS = "^[a-z ]+$";
10+
11+
@RepeatedTest(10)
12+
void testHeight() {
13+
assertThat(faker.measurement().height()).matches(WORDS);
14+
}
15+
16+
@RepeatedTest(10)
17+
void testLength() {
18+
assertThat(faker.measurement().length()).matches(WORDS);
19+
}
20+
21+
@RepeatedTest(10)
22+
void testVolume() {
23+
assertThat(faker.measurement().volume()).matches(WORDS);
24+
}
25+
26+
@RepeatedTest(10)
27+
void testWeight() {
28+
assertThat(faker.measurement().weight()).matches(WORDS);
29+
}
30+
31+
@RepeatedTest(10)
32+
void testMetricHeight() {
33+
assertThat(faker.measurement().metricHeight()).matches(WORDS);
34+
}
35+
36+
@RepeatedTest(10)
37+
void testMetricLength() {
38+
assertThat(faker.measurement().metricLength()).matches(WORDS);
39+
}
40+
41+
@RepeatedTest(10)
42+
void testMetricVolume() {
43+
assertThat(faker.measurement().metricVolume()).matches(WORDS);
44+
}
45+
46+
@RepeatedTest(10)
47+
void testMetricWeight() {
48+
assertThat(faker.measurement().metricWeight()).matches(WORDS);
49+
}
50+
}

src/test/java/net/datafaker/integration/FakerIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ void testAllFakerMethodsThatReturnStrings(Locale locale, Random random) throws E
150150
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.lorem());
151151
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.marketing());
152152
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.matz());
153+
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.measurement());
153154
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.military());
154155
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.mountain());
155156
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.mountaineering());

0 commit comments

Comments
 (0)