Skip to content

Commit 1f4db90

Browse files
committed
Food component
1 parent c197d50 commit 1f4db90

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The goal was to reuse their locale data files.
1717
}
1818

1919
dependencies {
20-
compile 'com.github.blocoio:faker:1.2.5'
20+
compile 'com.github.blocoio:faker:1.2.6'
2121
}
2222

2323
You can use ```testCompile``` or ```androidTestCompile```, if you only want to use Faker for testing.
@@ -46,6 +46,7 @@ We have tried to keep the operations as close as possible.
4646
- Commerce
4747
- Company
4848
- Date
49+
- Food
4950
- Internet
5051
- Lorem
5152
- Name

src/main/java/io/bloco/faker/Faker.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.bloco.faker.components.Commerce;
2323
import io.bloco.faker.components.Company;
2424
import io.bloco.faker.components.Date;
25+
import io.bloco.faker.components.Food;
2526
import io.bloco.faker.components.Internet;
2627
import io.bloco.faker.components.Lorem;
2728
import io.bloco.faker.components.Name;
@@ -48,6 +49,7 @@ public class Faker {
4849
public final Commerce commerce;
4950
public final Company company;
5051
public final Date date;
52+
public final Food food;
5153
public final Internet internet;
5254
public final Lorem lorem;
5355
public final Name name;
@@ -87,6 +89,7 @@ public Faker(String locale) {
8789
this.commerce = this.data.getComponent(Commerce.class);
8890
this.company = this.data.getComponent(Company.class);
8991
this.date = this.data.getComponent(Date.class);
92+
this.food = this.data.getComponent(Food.class);
9093
this.internet = this.data.getComponent(Internet.class);
9194
this.lorem = this.data.getComponent(Lorem.class);
9295
this.name = this.data.getComponent(Name.class);

src/main/java/io/bloco/faker/FakerData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.bloco.faker.components.Commerce;
1414
import io.bloco.faker.components.Company;
1515
import io.bloco.faker.components.Date;
16+
import io.bloco.faker.components.Food;
1617
import io.bloco.faker.components.Internet;
1718
import io.bloco.faker.components.Lorem;
1819
import io.bloco.faker.components.Name;
@@ -46,6 +47,7 @@ public FakerData(Map<String, Object> data) {
4647
new Commerce(this),
4748
new Company(this),
4849
new Date(this),
50+
new Food(this),
4951
new Internet(this),
5052
new Lorem(this),
5153
new Name(this),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.bloco.faker.components;
2+
3+
import io.bloco.faker.FakerComponent;
4+
import io.bloco.faker.FakerData;
5+
6+
public class Food extends FakerComponent {
7+
8+
public Food(FakerData data) {
9+
super(data);
10+
}
11+
12+
public String dish() {
13+
return fetch("food.dish");
14+
}
15+
16+
public String description() {
17+
return fetch("food.descriptions");
18+
}
19+
20+
public String ingredient() {
21+
return fetch("food.ingredients");
22+
}
23+
24+
public String spice() {
25+
return fetch("food.spices");
26+
}
27+
28+
public String measurement() {
29+
return fetch("food.measurement_sizes") + " " + fetch("food.measurements");
30+
}
31+
32+
public String metricMeasurement() {
33+
return fetch("food.metric_measurements");
34+
}
35+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package io.bloco.faker.components;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
6+
import io.bloco.faker.Faker;
7+
8+
import static io.bloco.faker.test_helpers.RegularExpressionMatcher.matchesPattern;
9+
import static org.junit.Assert.assertNotNull;
10+
import static org.junit.Assert.assertThat;
11+
12+
public class FoodTest {
13+
14+
private Faker faker;
15+
16+
@Before
17+
public void setUp() {
18+
faker = new Faker();
19+
}
20+
21+
@Test
22+
public void dish() {
23+
assertNotNull(faker.food.dish());
24+
}
25+
26+
@Test
27+
public void description() {
28+
assertNotNull(faker.food.description());
29+
}
30+
31+
@Test
32+
public void ingredient() {
33+
assertNotNull(faker.food.ingredient());
34+
}
35+
36+
@Test
37+
public void spice() {
38+
assertNotNull(faker.food.spice());
39+
}
40+
41+
@Test
42+
public void measurement() {
43+
assertNotNull(faker.food.measurement());
44+
assertThat(faker.food.measurement(), matchesPattern("[\\d\\/]+ \\w+"));
45+
}
46+
47+
@Test
48+
public void metricMeasurement() {
49+
assertNotNull(faker.food.metricMeasurement());
50+
}
51+
}

0 commit comments

Comments
 (0)