Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/garment size faker #742

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Fakers
* Friends
* FunnyName
* GameOfThrones
* GarmentSize
* Gender
* Hacker
* HarryPotter
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/github/javafaker/Faker.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Faker {
private final Finance finance;
private final Food food;
private final GameOfThrones gameOfThrones;
private final GarmentSize garmentSize;
private final Gender gender;
private final DateAndTime dateAndTime;
private final Demographic demographic;
Expand Down Expand Up @@ -162,6 +163,7 @@ public Faker(FakeValuesService fakeValuesService, RandomService random) {
this.finance = new Finance(this);
this.food = new Food(this);
this.gameOfThrones = new GameOfThrones(this);
this.garmentSize = new GarmentSize(this);
this.gender = new Gender(this);
this.dateAndTime = new DateAndTime(this);
this.demographic = new Demographic(this);
Expand Down Expand Up @@ -471,6 +473,8 @@ public GameOfThrones gameOfThrones() {
return gameOfThrones;
}

public GarmentSize garmentSize() { return garmentSize; }

public Gender gender() {
return gender;
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/github/javafaker/GarmentSize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.javafaker;


/**
* This class is used to generate garments sizes randomly.
*
*/

public class GarmentSize {
private final Faker faker;

protected GarmentSize(Faker faker) {
this.faker = faker;
}

/**
* This method returns a garment size
*
* @return a string of garment size
*/
public String size() {
return faker.fakeValuesService().fetchString("garments.sizes");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public String getPath() {
"friends.yml",
"funny_name.yml",
"game_of_thrones.yml",
"garments_sizes.yml",
"gender.yml",
"ghostbusters.yml",
"grateful_dead.yml",
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/en/garments_sizes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
faker:
garments:
sizes: ["XS", "S", "M", "L", "XL", "XXL", "XXXL"]
14 changes: 14 additions & 0 deletions src/test/java/com/github/javafaker/GarmentSizeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.javafaker;


import org.junit.Test;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static org.junit.Assert.assertThat;

public class GarmentSizeTest extends AbstractFakerTest {

@Test
public void sizes() {
assertThat(faker.garmentSize().size(), matchesRegularExpression("([A-Z]+)"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void testAllFakerMethodsThatReturnStrings() throws Exception {
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.finance());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.food());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.gameOfThrones());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.garmentSize());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.gender());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.hacker());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.idNumber());
Expand Down