Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c07275e4fb | |||
| 9e23a7a161 | |||
| f8b4077785 | |||
| 09f00741cf | |||
| 069aed2300 | |||
| 0e60758671 | |||
| 272bd7acee | |||
| 5bbfbeeb39 | |||
| e6f798f85e | |||
| 3d92dfb33b | |||
| be339360de | |||
| f2be8022c2 | |||
| 4c61966b1c | |||
| 196a5ce4bd | |||
| cb3cb744e8 | |||
| a0bca97ace | |||
| 3d3204b2bc | |||
| 309f109707 | |||
| df2876d8dd | |||
| aa1735a6b5 | |||
| 488048254b | |||
| 25dfd23d2c | |||
| 9b480b997e | |||
| 02ba126596 | |||
| b3c6b7c534 | |||
| 48bbe2aeb9 | |||
| fa44670b41 |
@@ -6,3 +6,5 @@ target
|
||||
*.iml
|
||||
.java-version
|
||||
/dependency-reduced-pom.xml
|
||||
META-INF/
|
||||
bin/
|
||||
|
||||
@@ -17,7 +17,7 @@ In pom.xml, add the following xml stanza between `<dependencies> ... </dependenc
|
||||
<dependency>
|
||||
<groupId>com.github.javafaker</groupId>
|
||||
<artifactId>javafaker</artifactId>
|
||||
<version>0.18</version>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -25,7 +25,7 @@ For gradle users, add the following to your build.gradle file.
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.github.javafaker:javafaker:0.18'
|
||||
implementation 'com.github.javafaker:javafaker:1.0.0'
|
||||
}
|
||||
|
||||
```
|
||||
@@ -42,6 +42,8 @@ String lastName = faker.name().lastName(); // Barton
|
||||
String streetAddress = faker.address().streetAddress(); // 60018 Sawayn Brooks Suite 449
|
||||
```
|
||||
|
||||
This is a [demo web application](https://java-faker.herokuapp.com/) that uses the library.
|
||||
|
||||
Javadoc
|
||||
-----
|
||||
http://dius.github.io/java-faker/apidocs/index.html
|
||||
@@ -55,10 +57,12 @@ See [CONTRIBUTING.md](https://github.com/DiUS/java-faker/blob/master/CONTRIBUTIN
|
||||
Fakers
|
||||
-----
|
||||
* Ancient
|
||||
* Animal
|
||||
* Address
|
||||
* App
|
||||
* Artist
|
||||
* Avatar
|
||||
* Back To The Future
|
||||
* Aviation
|
||||
* Beer
|
||||
* Book
|
||||
@@ -104,6 +108,8 @@ Fakers
|
||||
* Overwatch
|
||||
* PhoneNumber
|
||||
* Pokemon
|
||||
* Princess Bride
|
||||
* Relationship Terms
|
||||
* RickAndMorty
|
||||
* Robin
|
||||
* RockBand
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
public class Animal {
|
||||
private final Faker faker;
|
||||
|
||||
protected Animal(Faker faker) {
|
||||
this.faker = faker;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return faker.fakeValuesService().resolve("creature.animal.name", this, faker);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
public class Buffy {
|
||||
private final Faker faker;
|
||||
|
||||
protected Buffy(Faker faker) {
|
||||
this.faker = faker;
|
||||
}
|
||||
|
||||
public String characters() {
|
||||
return faker.fakeValuesService().resolve("buffy.characters", this, faker);
|
||||
}
|
||||
|
||||
public String quotes() {
|
||||
return faker.fakeValuesService().resolve("buffy.quotes", this, faker);
|
||||
}
|
||||
|
||||
public String celebrities() {
|
||||
return faker.fakeValuesService().resolve("buffy.celebrities", this, faker);
|
||||
}
|
||||
|
||||
public String bigBads() {
|
||||
return faker.fakeValuesService().resolve("buffy.big_bads", this, faker);
|
||||
}
|
||||
|
||||
public String episodes() {
|
||||
return faker.fakeValuesService().resolve("buffy.episodes", this, faker);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
public class ElderScrolls {
|
||||
|
||||
private final Faker faker;
|
||||
|
||||
protected ElderScrolls(Faker faker) {
|
||||
this.faker = faker;
|
||||
}
|
||||
|
||||
public String race() {
|
||||
return faker.fakeValuesService().resolve("games.elder_scrolls.race", this, faker);
|
||||
}
|
||||
|
||||
public String creature() {
|
||||
return faker.fakeValuesService().resolve("games.elder_scrolls.creature", this, faker);
|
||||
}
|
||||
|
||||
public String region() {
|
||||
return faker.fakeValuesService().resolve("games.elder_scrolls.region", this, faker);
|
||||
}
|
||||
|
||||
public String dragon() {
|
||||
return faker.fakeValuesService().resolve("games.elder_scrolls.dragon", this, faker);
|
||||
}
|
||||
|
||||
public String city() {
|
||||
return faker.fakeValuesService().resolve("games.elder_scrolls.city", this, faker);
|
||||
}
|
||||
|
||||
public String firstName() {
|
||||
return faker.fakeValuesService().resolve("games.elder_scrolls.first_name", this, faker);
|
||||
}
|
||||
|
||||
public String lastName() {
|
||||
return faker.fakeValuesService().resolve("games.elder_scrolls.last_name", this, faker);
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ public class Faker {
|
||||
private final Demographic demographic;
|
||||
private final Dog dog;
|
||||
private final Educator educator;
|
||||
private final ElderScrolls elderScrolls;
|
||||
private final Shakespeare shakespeare;
|
||||
private final SlackEmoji slackEmoji;
|
||||
private final Space space;
|
||||
@@ -85,7 +86,11 @@ public class Faker {
|
||||
private final Weather weather;
|
||||
private final Lebowski lebowski;
|
||||
private final Medical medical;
|
||||
private final Animal animal;
|
||||
private final BackToTheFuture backToTheFuture;
|
||||
private final PrincessBride princessBride;
|
||||
private final Buffy buffy;
|
||||
private final Relationships relationships;
|
||||
|
||||
public Faker() {
|
||||
this(Locale.ENGLISH);
|
||||
@@ -124,6 +129,7 @@ public class Faker {
|
||||
this.hacker = new Hacker(this);
|
||||
this.company = new Company(this);
|
||||
this.crypto = new Crypto(this);
|
||||
this.elderScrolls = new ElderScrolls(this);
|
||||
this.commerce = new Commerce(this);
|
||||
this.currency = new Currency(this);
|
||||
this.options = new Options(this);
|
||||
@@ -172,7 +178,11 @@ public class Faker {
|
||||
this.lebowski = new Lebowski(this);
|
||||
this.medical = new Medical(this);
|
||||
this.country = new Country(this);
|
||||
this.animal = new Animal(this);
|
||||
this.backToTheFuture = new BackToTheFuture(this);
|
||||
this.princessBride = new PrincessBride(this);
|
||||
this.buffy = new Buffy(this);
|
||||
this.relationships = new Relationships(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,6 +363,10 @@ public class Faker {
|
||||
return book;
|
||||
}
|
||||
|
||||
public Buffy buffy() {
|
||||
return buffy;
|
||||
}
|
||||
|
||||
public Business business() {
|
||||
return business;
|
||||
}
|
||||
@@ -405,6 +419,10 @@ public class Faker {
|
||||
return food;
|
||||
}
|
||||
|
||||
public ElderScrolls elderScrolls() {
|
||||
return elderScrolls;
|
||||
}
|
||||
|
||||
public GameOfThrones gameOfThrones() {
|
||||
return gameOfThrones;
|
||||
}
|
||||
@@ -565,10 +583,20 @@ public class Faker {
|
||||
|
||||
public Country country(){ return country;}
|
||||
|
||||
public Animal animal(){ return animal; }
|
||||
|
||||
public BackToTheFuture backToTheFuture() {
|
||||
return backToTheFuture;
|
||||
}
|
||||
|
||||
public PrincessBride princessBride() {
|
||||
return princessBride;
|
||||
}
|
||||
|
||||
public Relationships relationships() {
|
||||
return relationships;
|
||||
}
|
||||
|
||||
public String resolve(String key) {
|
||||
return this.fakeValuesService.resolve(key, this, this);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
public class PrincessBride {
|
||||
private final Faker faker;
|
||||
|
||||
protected PrincessBride(Faker faker) {
|
||||
this.faker = faker;
|
||||
}
|
||||
|
||||
public String character() {
|
||||
return faker.resolve("princess_bride.characters");
|
||||
}
|
||||
|
||||
public String quote() {
|
||||
return faker.resolve("princess_bride.quotes");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
public class Relationships {
|
||||
private final Faker faker;
|
||||
|
||||
protected Relationships(final Faker faker) {
|
||||
this.faker = faker;
|
||||
}
|
||||
|
||||
public String direct() {
|
||||
return faker.resolve("relationship.familial.direct");
|
||||
}
|
||||
|
||||
public String extended() {
|
||||
return faker.resolve("relationship.familial.extended");
|
||||
}
|
||||
|
||||
public String inLaw() {
|
||||
return faker.resolve("relationship.in_law");
|
||||
}
|
||||
|
||||
public String spouse() {
|
||||
return faker.resolve("relationship.spouse");
|
||||
}
|
||||
|
||||
public String parent() {
|
||||
return faker.resolve("relationship.parent");
|
||||
}
|
||||
|
||||
public String sibling() {
|
||||
return faker.resolve("relationship.sibling");
|
||||
}
|
||||
|
||||
public String any() {
|
||||
Method currentMethod = Relationships.class.getClass().getEnclosingMethod();
|
||||
|
||||
try {
|
||||
Method[] methods = Relationships.class.getDeclaredMethods();
|
||||
methods = ArrayUtils.removeElement(methods, currentMethod);
|
||||
int indx = faker.random().nextInt(methods.length);
|
||||
Method runMethod = methods[indx];
|
||||
Relationships relationships = new Relationships(faker);
|
||||
return (String)runMethod.invoke(relationships);
|
||||
} catch (SecurityException e) {
|
||||
throw new RuntimeException("SecurityException: " + e.getMessage());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException("IllegalArgumentException: " + e.getMessage());
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException("IllegalAccessException: " + e.getMessage());
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException("InvocationTargetException: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -177,6 +177,7 @@ public class EnFile {
|
||||
|
||||
// files where the search path can't be derived from the filename
|
||||
private static List<EnFile> FILES_WITH_A_DIFFERENT_PATH = Arrays.asList(
|
||||
new EnFile("animal.yml", "creature"),
|
||||
new EnFile("cat.yml", "creature"),
|
||||
new EnFile("dog.yml", "creature"),
|
||||
new EnFile("league_of_legends.yml", "games"),
|
||||
@@ -184,6 +185,7 @@ public class EnFile {
|
||||
new EnFile("pokemon.yml", "games"),
|
||||
new EnFile("witcher.yml", "games"),
|
||||
new EnFile("zelda.yml", "games"),
|
||||
new EnFile("elder_scrolls.yml", "games"),
|
||||
new EnFile("phone_number.yml", "cell_phone")); // load phone number again with a differen path
|
||||
|
||||
|
||||
|
||||
@@ -65,6 +65,10 @@ de:
|
||||
- "#{half_wind_azimuth}"
|
||||
- "#{quarter_wind_azimuth}"
|
||||
|
||||
creature:
|
||||
animal:
|
||||
name: ["Aal", "Adler", "Affe", "Affe", "Alligator", "Alpaka", "Ameise", "Antilope", "Ara", "Auster", "Biber", "Biene", "Bisamratte", "Bär", "Büffel", "Chinchilla", "Dachs", "Delphin", "Dinosaurier", "Eichhörnchen", "Eidechse", "Elch", "Elch", "Elch", "Elefant", "Ente", "Esel", "Fisch", "Fledermaus", "Fliege", "Forelle", "Frettchen", "Frosch", "Fuchs", "Gans", "Gepard", "Giraffe", "Gnu", "Goldfisch", "Gorilla", "Grille", "Gürteltier", "Hai", "Hamster", "Hase", "Hering", "Heuschrecke", "Heuschrecke", "Hirsch", "Hornisse", "Hund", "Hyäne", "Igel", "Impala", "Jagdhund", "Kabeljau", "Kakerlake", "Kamel", "Kaninchen", "Karibu", "Katze", "Koala", "Kojote", "Krabbe", "Krokodil", "Krähe", "Kröte", "Käfer", "Känguru", "Lachs", "Lama", "Landschildkröte", "Laus", "Leopard", "Löwe", "Mammut", "Marder", "Maultier", "Maulwurf", "Maus", "Meerschweinchen", "Mops", "Muschel", "Mücke", "Mücke", "Nashorn", "Nerz", "Nilpferd", "Otter", "Panda", "Pavian", "Pferd", "Präriehund", "Qualle", "Rabe", "Ratte", "Rennmaus", "Rentier", "Rind", "Rind", "Robbe", "Sardine", "Schaf", "Schakal", "Schildkröte", "Schimpanse", "Schlange", "Schmetterling", "Schnabeltier", "Schnecke", "Schwan", "Schwein", "Schweinswal", "Seekuh", "Seelöwe", "Serval", "Skorpion", "Spinne", "Stachelschwein", "Stinktier", "Stockente", "Termite", "Tiger", "Wal", "Waldmurmeltier", "Wallaby", "Walross", "Waschbär", "Wasserbüffel", "Wespe", "Wespe", "Wiesel", "Wolf", "Wombat", "Wurm", "Yak", "Zebra", "Ziege", "Zikade"]
|
||||
|
||||
internet:
|
||||
free_email: [gmail.com, yahoo.com, hotmail.com, gmx.de, web.de, mail.de, freenet.de]
|
||||
domain_suffix: [com, info, name, net, org, de, ch]
|
||||
|
||||
Executable → Regular
@@ -110,6 +110,6 @@ public class AddressTest extends AbstractFakerTest {
|
||||
@Test
|
||||
public void testCountyByZipCode() {
|
||||
faker = new Faker(new Locale("en-US"));
|
||||
assertThat(faker.address().countyByZipCode(faker.address().zipCodeByState(faker.address().stateAbbr())), not(isEmptyOrNullString()));
|
||||
assertThat(faker.address().countyByZipCode("47732"), not(isEmptyOrNullString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 AnimalTest extends AbstractFakerTest {
|
||||
|
||||
@Test
|
||||
public void name() {
|
||||
assertThat(faker.animal().name(), matchesRegularExpression("[A-Za-z ]+"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.github.javafaker.matchers.IsStringWithContents.isStringWithContents;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class BuffyTest extends AbstractFakerTest {
|
||||
@Test
|
||||
public void testCharacters() {
|
||||
assertThat(faker.buffy().characters(), isStringWithContents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuotes() {
|
||||
assertThat(faker.buffy().quotes(), isStringWithContents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCelebrities() {
|
||||
assertThat(faker.buffy().celebrities(), isStringWithContents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigBads() {
|
||||
assertThat(faker.buffy().bigBads(), isStringWithContents());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEpisodes() {
|
||||
assertThat(faker.buffy().episodes(), isStringWithContents());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class ElderScrollsTest extends AbstractFakerTest {
|
||||
|
||||
@Test
|
||||
public void testCity() {
|
||||
assertThat(faker.elderScrolls().city(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreature() {
|
||||
assertThat(faker.elderScrolls().creature(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDragon() {
|
||||
assertThat(faker.elderScrolls().dragon(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstName() {
|
||||
assertThat(faker.elderScrolls().firstName(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLastName() {
|
||||
assertThat(faker.elderScrolls().lastName(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRace() {
|
||||
assertThat(faker.elderScrolls().race(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegion() {
|
||||
assertThat(faker.elderScrolls().region(), not(isEmptyOrNullString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class PrincessBrideTest extends AbstractFakerTest {
|
||||
@Test
|
||||
public void character() {
|
||||
assertThat(faker.princessBride().character(), matchesRegularExpression("[A-Za-z .-]+"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void quote() {
|
||||
assertThat(faker.princessBride().quote(), not(isEmptyOrNullString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import static org.hamcrest.Matchers.isEmptyOrNullString;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RelationshipTest extends AbstractFakerTest {
|
||||
|
||||
@Test
|
||||
public void anyTest() {
|
||||
assertThat(faker.relationships().any(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directTest() {
|
||||
assertThat(faker.relationships().direct(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extendedTest() {
|
||||
assertThat(faker.relationships().extended(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inLawTest() {
|
||||
assertThat(faker.relationships().inLaw(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spouseTest() {
|
||||
assertThat(faker.relationships().spouse(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parentTest() {
|
||||
assertThat(faker.relationships().parent(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void siblingTest() {
|
||||
assertThat(faker.relationships().sibling(), not(isEmptyOrNullString()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class FakerIT {
|
||||
/**
|
||||
* a collection of Locales -> Exceptions.
|
||||
* In the case of 'pt', city_prefix is '' by design. This test fails because it's testing that all string returning
|
||||
* methods return a non blank string. But pt city_prefix is blank ,but the test shouldn't fail. So we add put
|
||||
* methods return a non blank string. But pt city_prefix is blank ,but the test shouldn't fail. So we add put
|
||||
* exceptions like this into this collection.
|
||||
*/
|
||||
private static final Map<Locale, List<String>> exceptions = Maps.newHashMap();
|
||||
@@ -152,6 +152,11 @@ public class FakerIT {
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.witcher());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.weather());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.lebowski());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.animal());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.princessBride());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.elderScrolls());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.buffy());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.relationships());
|
||||
}
|
||||
|
||||
private void testAllMethodsThatReturnStringsActuallyReturnStrings(Object object) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user