Merge branch 'worker_peng' of https://github.com/JinquanPeng/java-faker into JinquanPeng-worker_peng
This commit is contained in:
@@ -93,6 +93,7 @@ Fakers
|
||||
* Friends
|
||||
* FunnyName
|
||||
* GameOfThrones
|
||||
* Gender
|
||||
* Hacker
|
||||
* HarryPotter
|
||||
* Hipster
|
||||
|
||||
@@ -46,6 +46,7 @@ public class Faker {
|
||||
private final Finance finance;
|
||||
private final Food food;
|
||||
private final GameOfThrones gameOfThrones;
|
||||
private final Gender gender;
|
||||
private final DateAndTime dateAndTime;
|
||||
private final Demographic demographic;
|
||||
private final Dog dog;
|
||||
@@ -106,7 +107,7 @@ public class Faker {
|
||||
}
|
||||
|
||||
public Faker(Locale locale) {
|
||||
this(locale, (Random)null);
|
||||
this(locale, (Random) null);
|
||||
}
|
||||
|
||||
public Faker(Random random) {
|
||||
@@ -155,6 +156,7 @@ public class Faker {
|
||||
this.finance = new Finance(this);
|
||||
this.food = new Food(this);
|
||||
this.gameOfThrones = new GameOfThrones(this);
|
||||
this.gender = new Gender(this);
|
||||
this.dateAndTime = new DateAndTime(this);
|
||||
this.demographic = new Demographic(this);
|
||||
this.dog = new Dog(this);
|
||||
@@ -457,6 +459,10 @@ public class Faker {
|
||||
return gameOfThrones;
|
||||
}
|
||||
|
||||
public Gender gender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public DateAndTime date() {
|
||||
return dateAndTime;
|
||||
}
|
||||
@@ -607,14 +613,20 @@ public class Faker {
|
||||
return lebowski;
|
||||
}
|
||||
|
||||
public Medical medical(){return medical;}
|
||||
public Medical medical() {
|
||||
return medical;
|
||||
}
|
||||
|
||||
public Country country(){ return country;}
|
||||
public Country country() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public Animal animal(){ return animal; }
|
||||
public Animal animal() {
|
||||
return animal;
|
||||
}
|
||||
|
||||
public BackToTheFuture backToTheFuture() {
|
||||
return backToTheFuture;
|
||||
return backToTheFuture;
|
||||
}
|
||||
|
||||
public PrincessBride princessBride() {
|
||||
@@ -674,4 +686,4 @@ public class Faker {
|
||||
public String expression(String expression) {
|
||||
return this.fakeValuesService.expression(expression, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
/**
|
||||
* This class is used to generate gender randomly.
|
||||
*
|
||||
* @author Peng
|
||||
*/
|
||||
|
||||
public class Gender {
|
||||
private final Faker faker;
|
||||
|
||||
protected Gender(Faker faker) {
|
||||
this.faker = faker;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a gender type
|
||||
*
|
||||
* @return a string of gender type
|
||||
*/
|
||||
public String types() {
|
||||
|
||||
return faker.fakeValuesService().fetchString("gender.types");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a binary gender type
|
||||
*
|
||||
* @return a string of binary gender type
|
||||
*/
|
||||
public String binaryTypes() {
|
||||
|
||||
return faker.fakeValuesService().fetchString("gender.binary_types");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a short binary gender type
|
||||
*
|
||||
* @return a string of short binary gender type
|
||||
*/
|
||||
public String shortBinaryTypes() {
|
||||
|
||||
return faker.fakeValuesService().fetchString("gender.short_binary_types");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
en:
|
||||
faker:
|
||||
gender:
|
||||
types: ["Female", "Male", "Non-binary", "Agender", "Genderfluid", "Genderqueer", "Bigender", "Polygender"]
|
||||
binary_types: ["Female", "Male"]
|
||||
en:
|
||||
faker:
|
||||
gender:
|
||||
types: ["Female", "Male", "NonBinary", "Agender", "Genderfluid", "Genderqueer", "Bigender", "Polygender"]
|
||||
binary_types: ["Female", "Male"]
|
||||
short_binary_types: ["f", "m"]
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class GenderTest extends AbstractFakerTest {
|
||||
|
||||
@Test
|
||||
public void types() {
|
||||
assertThat(faker.gender().types(), matchesRegularExpression("(\\w+ ?){1,2}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void binaryTypes() {
|
||||
assertThat(faker.gender().binaryTypes(), matchesRegularExpression("[A-Za-z ]+"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortBinaryTypes() {
|
||||
assertThat(faker.gender().shortBinaryTypes(), matchesRegularExpression("f|m"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -126,6 +126,7 @@ public class FakerIT {
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.finance());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.food());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.gameOfThrones());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.gender());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.hacker());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.idNumber());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.shakespeare());
|
||||
|
||||
Reference in New Issue
Block a user