Skip to content

Commit

Permalink
Merge 1bd3d12 into 1850b03
Browse files Browse the repository at this point in the history
  • Loading branch information
XiShao-art committed May 8, 2020
2 parents 1850b03 + 1bd3d12 commit 3ca8787
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/github/javafaker/Faker.java
Expand Up @@ -97,6 +97,7 @@ public class Faker {
private final AquaTeenHungerForce aquaTeenHungerForce;
private final ProgrammingLanguage programmingLanguage;
private final Kaamelott kaamelott;
private final Gender gender;

public Faker() {
this(Locale.ENGLISH);
Expand Down Expand Up @@ -203,6 +204,7 @@ public Faker(FakeValuesService fakeValuesService, RandomService random) {
this.aquaTeenHungerForce = new AquaTeenHungerForce(this);
this.programmingLanguage = new ProgrammingLanguage(this);
this.kaamelott = new Kaamelott(this);
this.gender=new Gender(this);
}

/**
Expand Down Expand Up @@ -641,6 +643,8 @@ public Kaamelott kaamelott() {
return kaamelott;
}

public Gender gender(){return gender;}

public String resolve(String key) {
return this.fakeValuesService.resolve(key, this, this);
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/github/javafaker/Gender.java
@@ -0,0 +1,34 @@
package com.github.javafaker;

public class Gender {

private final Faker faker;

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

/**
* <p>
* A gender which maybe special. Examples:
* <ul>
* <li>Non-binary</li>
* <li>Genderfluid</li>
* </ul>
* </p>
* @return a random gender.
*/
public String types() { return faker.fakeValuesService().resolve("gender.types", this, faker); }

/**
* <p>
* A gender which if male or female. Examples:
* <ul>
* <li>male</li>
* <li>female</li>
* </ul>
* </p>
* @return a random binary gender.
*/
public String binarytypes() {
return faker.fakeValuesService().resolve("gender.binary_types", this, faker);
}
}
15 changes: 15 additions & 0 deletions src/test/java/com/github/javafaker/GenderTest.java
@@ -0,0 +1,15 @@
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 testType() { assertThat(faker.gender().types(), matchesRegularExpression("([\\w-]+ ?)+")); }

@Test
public void testBinarytypes() { assertThat(faker.gender().binarytypes(), matchesRegularExpression("([\\w-]+ ?)+")); }

}

0 comments on commit 3ca8787

Please sign in to comment.