Skip to content

Commit 8466d52

Browse files
committed
#1708 fix test failing because some product might have space in name
1 parent 60d2f95 commit 8466d52

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/test/java/net/datafaker/providers/base/CommerceTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.Collection;
66
import java.util.List;
7+
import java.util.Locale;
78

89
import static java.lang.Float.parseFloat;
910
import static org.assertj.core.api.Assertions.assertThat;
@@ -15,7 +16,6 @@ class CommerceTest extends BaseFakerTest {
1516
private static final String PROMOTION_CODE_REGEX = CAPITALIZED_WORD_REGEX + "(-" + CAPITALIZED_WORD_REGEX + ")*";
1617

1718
private final Commerce commerce = faker.commerce();
18-
private final String[] commerceProductName = commerce.productName().split(" ");
1919

2020
@Test
2121
void testDepartment() {
@@ -27,14 +27,27 @@ void testProductName() {
2727
assertThat(commerce.productName()).matches("(\\w+ ?){3,4}");
2828
}
2929

30+
@Test
31+
void productNameConsistsOf_adjective_material_and_productType() {
32+
BaseFaker faker = new BaseFaker(new Locale("test"));
33+
assertThat(faker.commerce().productName()).isIn(
34+
"Silver Linings Playbook",
35+
"Silver Linings Train",
36+
"Silver Iron Playbook",
37+
"Silver Iron Train",
38+
"Silent Linings Playbook",
39+
"Silent Linings Train",
40+
"Silent Iron Playbook",
41+
"Silent Iron Train"
42+
);
43+
}
44+
3045
@Override
3146
protected Collection<TestSpec> providerListTest() {
3247
return List.of(TestSpec.of(commerce::material, "commerce.product_name.material"),
3348
TestSpec.of(commerce::brand, "commerce.brand"),
34-
TestSpec.of(commerce::vendor, "commerce.vendor"),
35-
TestSpec.of(() -> commerceProductName[0], "commerce.product_name.adjective"),
36-
TestSpec.of(() -> commerceProductName[1], "commerce.product_name.material"),
37-
TestSpec.of(() -> commerceProductName[2], "commerce.product_name.product"));
49+
TestSpec.of(commerce::vendor, "commerce.vendor")
50+
);
3851
}
3952

4053
@Test

src/test/resources/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ test:
5656
- 12.34
5757
valid-boolean:
5858
- true
59+
commerce:
60+
product_name:
61+
adjective:
62+
- "Silver"
63+
- "Silent"
64+
material:
65+
- "Linings"
66+
- "Iron"
67+
product:
68+
- "Playbook"
69+
- "Train"

0 commit comments

Comments
 (0)