Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 09cff31e38 | |||
| d1557c1a8f | |||
| 15c4071c28 | |||
| 140915be49 | |||
| e0bfbf91a9 | |||
| ba001e1d2b | |||
| fba9cbc6b6 | |||
| 7fc5e07284 | |||
| 27850c0477 | |||
| 6aab9d1842 | |||
| 1038556ac1 | |||
| fc96c78267 | |||
| abfb547d1c | |||
| f8191d4ae5 | |||
| 65b2ba2a85 | |||
| 203f437ee0 | |||
| fee1da2eb6 | |||
| f506d8d161 | |||
| c51f0ef359 | |||
| 0ce50126b6 | |||
| 3c5883e42a | |||
| 7eef1701b5 | |||
| 17a71fedf3 | |||
| c48bb870e6 | |||
| b0380c400d | |||
| 93c1d32b88 | |||
| edd4269948 | |||
| ccb2387b7e | |||
| f448d1cbfd | |||
| b0da70ac37 | |||
| 59bd587c61 | |||
| de372e5d76 | |||
| 4b97108305 | |||
| 58cbe405d2 | |||
| c44c09a5a1 | |||
| dd3237e64e | |||
| 4dfe0834db | |||
| a562271ad7 | |||
| 376d75267a | |||
| 0b11d351cc |
@@ -2,6 +2,3 @@ target
|
||||
.project
|
||||
.classpath
|
||||
.settings
|
||||
.idea/
|
||||
*.iml
|
||||
.java-version
|
||||
+6
-12
@@ -1,16 +1,10 @@
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk7
|
||||
- oraclejdk8
|
||||
- openjdk7
|
||||
- openjdk6
|
||||
branches:
|
||||
except:
|
||||
- travis
|
||||
- oraclejdk7
|
||||
- oraclejdk8
|
||||
- openjdk7
|
||||
- openjdk6
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
after_success:
|
||||
- mvn clean cobertura:cobertura coveralls:cobertura
|
||||
env:
|
||||
global:
|
||||
secure: BN4ubmSkpNY/nzaZO3zGiVK+9xhX/O5pWqFk7llUGaAmDw1dNiTrVWMdzaGxmAJa+v1US5vdwLx8ZQMlO6crp3T1VGOwEM2J5vFDPtyMsKM1hC6yKYnJhlfskNznJBhWJZKaLd6FgbxaW08C0BedocD9uVnsPKHiOHn2FXUm8Hs=
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
Java Faker
|
||||
==========
|
||||
This library is a port of Ruby's stympy/faker gem (as well as Perl's Data::Faker library) that generates fake data.
|
||||
It's useful when you're developing a new project and need some pretty data for showcase.
|
||||
|
||||
Usage
|
||||
-----
|
||||
In pom.xml, add following between `<dependencies> ... </dependencies>`
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.javafaker</groupId>
|
||||
<artifactId>javafaker</artifactId>
|
||||
<version>0.2</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
In your Java code
|
||||
|
||||
```java
|
||||
Faker faker = new Faker();
|
||||
|
||||
String name = faker.name(); // Miss Samanta Schmidt
|
||||
String firstName = faker.firstName(); // Emory
|
||||
String lastName = faker.lastName(); // Barton
|
||||
|
||||
String streetAddress = faker.streetAddress(); // 60018 Sawayn Brooks Suite 449
|
||||
```
|
||||
|
||||
How to build
|
||||
------------
|
||||
1. Make sure Apache Maven 3 is installed. ($ mvn --version)
|
||||
2. $ mvn package
|
||||
@@ -0,0 +1,86 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.javafaker</groupId>
|
||||
<artifactId>javafaker</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.3</version>
|
||||
<name>Java Faker</name>
|
||||
<description>
|
||||
This library is a port of Ruby's stympy/faker gem (as well as Perl's Data::Faker library) that generates fake data.
|
||||
It's useful when you're developing a new project and need some pretty data for showcase.
|
||||
</description>
|
||||
<url>http://github.com/DiUS/java-faker</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
<scm>
|
||||
<connection>scm:git:git://github.com/DiUS/java-faker.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:DiUS/java-faker.git</developerConnection>
|
||||
<url>git://github.com/DiUS/java-faker.git</url>
|
||||
</scm>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>renshao</id>
|
||||
<name>Ren Shao</name>
|
||||
<email>renshao@gmail.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>7</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jyaml</groupId>
|
||||
<artifactId>jyaml</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
@@ -1,9 +0,0 @@
|
||||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
<servers>
|
||||
<server>
|
||||
<id>sonatype-nexus-snapshots</id>
|
||||
<username>${env.CI_DEPLOY_USERNAME}</username>
|
||||
<password>${env.CI_DEPLOY_PASSWORD}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
||||
@@ -0,0 +1,250 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.capitalize;
|
||||
import static org.apache.commons.lang.StringUtils.join;
|
||||
import static org.apache.commons.lang.math.RandomUtils.nextInt;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
import org.ho.yaml.Yaml;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Provides utility methods for generating fake strings, such as names, phone
|
||||
* numbers, addresses. generate random strings with given patterns
|
||||
*
|
||||
* @author ren
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public class Faker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Faker.class);
|
||||
private static final char[] METHOD_NAME_DELIMITERS = { '_' };
|
||||
|
||||
private Map<String, Object> fakeValuesMap;
|
||||
|
||||
public Faker() {
|
||||
this(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public Faker(Locale locale) {
|
||||
logger.info("Using default locale " + locale);
|
||||
String languageCode = locale.getLanguage();
|
||||
Map valuesMap = (Map) Yaml.load(findStream(languageCode + ".yml"));
|
||||
valuesMap = (Map) valuesMap.get(languageCode);
|
||||
fakeValuesMap = (Map<String, Object>) valuesMap.get("faker");
|
||||
}
|
||||
|
||||
private InputStream findStream(String filename) {
|
||||
InputStream streamOnClass = getClass().getResourceAsStream(filename);
|
||||
if (streamOnClass != null) {
|
||||
return streamOnClass;
|
||||
}
|
||||
return getClass().getClassLoader().getResourceAsStream(filename);
|
||||
}
|
||||
|
||||
public String numerify(String numberString) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < numberString.length(); i++) {
|
||||
if (numberString.charAt(i) == '#') {
|
||||
sb.append(RandomUtils.nextInt(10));
|
||||
} else {
|
||||
sb.append(numberString.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String letterify(String letterString) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < letterString.length(); i++) {
|
||||
if (letterString.charAt(i) == '?') {
|
||||
sb.append((char) (97 + RandomUtils.nextInt(26))); // a-z
|
||||
} else {
|
||||
sb.append(letterString.charAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String bothify(String string) {
|
||||
return letterify(numerify(string));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a random value from an array item specified by the key
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public Object fetch(String key) {
|
||||
List valuesArray = (List) fetchObject(key);
|
||||
return valuesArray.get(RandomUtils.nextInt(valuesArray.size()));
|
||||
}
|
||||
|
||||
public String fetchString(String key) {
|
||||
return (String) fetch(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the object selected by the key from yaml file.
|
||||
*
|
||||
* @param key
|
||||
* key contains path to an object. Path segment is separated by
|
||||
* dot. E.g. name.first_name
|
||||
* @return
|
||||
*/
|
||||
public Object fetchObject(String key) {
|
||||
String[] path = key.split("\\.");
|
||||
Object currentValue = fakeValuesMap;
|
||||
for (String pathSection : path) {
|
||||
currentValue = ((Map<String, Object>) currentValue).get(pathSection);
|
||||
}
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
List<String> nameFormat = (List<String>) fetch("name.formats");
|
||||
|
||||
String[] nameParts = new String[nameFormat.size()];
|
||||
for (int i = 0; i < nameParts.length; i++) {
|
||||
// remove leading colon
|
||||
String methodName = nameFormat.get(i).substring(1);
|
||||
// convert to camel case
|
||||
methodName = WordUtils.capitalizeFully(methodName, METHOD_NAME_DELIMITERS).replaceAll("_", "");
|
||||
methodName = methodName.substring(0, 1).toLowerCase() + methodName.substring(1);
|
||||
|
||||
try {
|
||||
nameParts[i] = (String) Faker.class.getDeclaredMethod(methodName, (Class[]) null).invoke(this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
String name = StringUtils.join(nameParts, " ");
|
||||
return name;
|
||||
}
|
||||
|
||||
public String firstName() {
|
||||
return fetchString("name.first_name");
|
||||
}
|
||||
|
||||
public String lastName() {
|
||||
return fetchString("name.last_name");
|
||||
}
|
||||
|
||||
public String prefix() {
|
||||
return fetchString("name.prefix");
|
||||
}
|
||||
|
||||
public String suffix() {
|
||||
return fetchString("name.suffix");
|
||||
}
|
||||
|
||||
public String phoneNumber() {
|
||||
return numerify(fetchString("phone_number.formats"));
|
||||
}
|
||||
|
||||
// lorem
|
||||
public List<String> words(int num) {
|
||||
List<String> words = (List<String>) fetchObject("lorem.words");
|
||||
List<String> returnList = new ArrayList();
|
||||
for (int i = 0; i < num; i++) {
|
||||
returnList.add(words.get(nextInt(words.size())));
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
public List<String> words() {
|
||||
return words(3);
|
||||
}
|
||||
|
||||
public String sentence(int wordCount) {
|
||||
return capitalize(join(words(wordCount + RandomUtils.nextInt(6)), " ") + ".");
|
||||
}
|
||||
|
||||
public String sentence() {
|
||||
return sentence(3);
|
||||
}
|
||||
|
||||
public List<String> sentences(int sentenceCount) {
|
||||
List<String> sentences = new ArrayList<String>(sentenceCount);
|
||||
for (int i = 0; i < sentenceCount; i++) {
|
||||
sentences.add(sentence());
|
||||
}
|
||||
return sentences;
|
||||
}
|
||||
|
||||
public String paragraph(int sentenceCount) {
|
||||
return join(sentences(sentenceCount + nextInt(3)), " ");
|
||||
}
|
||||
|
||||
public String paragraph() {
|
||||
return paragraph(3);
|
||||
}
|
||||
|
||||
public List<String> paragraphs(int paragraphCount) {
|
||||
List<String> paragraphs = new ArrayList<String>(paragraphCount);
|
||||
for (int i = 0; i < paragraphCount; i++) {
|
||||
paragraphs.add(paragraph());
|
||||
}
|
||||
return paragraphs;
|
||||
}
|
||||
|
||||
// address
|
||||
|
||||
public String streetName() {
|
||||
List<String> possibleStreetNames = new ArrayList<String>();
|
||||
possibleStreetNames.add(join(new Object[] { lastName(), streetSuffix() }, " "));
|
||||
possibleStreetNames.add(join(new Object[] { firstName(), streetSuffix() }, " "));
|
||||
return possibleStreetNames.get(nextInt(possibleStreetNames.size()));
|
||||
}
|
||||
|
||||
public String streetAddress(boolean includeSecondary) {
|
||||
String streetAddress = fetchString("address.street_address") + " " + streetName();
|
||||
if (includeSecondary) {
|
||||
streetAddress = streetAddress + " " + secondaryAddress();
|
||||
}
|
||||
return numerify(streetAddress);
|
||||
}
|
||||
|
||||
public String secondaryAddress() {
|
||||
return numerify(fetchString("address.secondary_address"));
|
||||
}
|
||||
|
||||
public String zipCode() {
|
||||
return bothify(fetchString("address.postcode"));
|
||||
}
|
||||
|
||||
public String streetSuffix() {
|
||||
return fetchString("address.street_suffix");
|
||||
}
|
||||
|
||||
public String citySuffix() {
|
||||
return fetchString("address.city_suffix");
|
||||
}
|
||||
|
||||
public String cityPrefix() {
|
||||
return fetchString("address.city_prefix");
|
||||
}
|
||||
|
||||
public String stateAbbr() {
|
||||
return fetchString("address.state_abbr");
|
||||
}
|
||||
|
||||
public String country() {
|
||||
return fetchString("address.country");
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,48 @@
|
||||
fr:
|
||||
faker:
|
||||
address:
|
||||
city_prefix: [Île, Provence, Midi, Ville, Lac, Chemin]
|
||||
city_suffix: [du Sud, du Nord, de France, de la Loire, de Calais, Alpes, d’Azur, de l'Est, de l'Ouest]
|
||||
country: [Afrique du Sud, Albanie, Australie, Belgique, Croatie, États-Unis, France, Gambon, Irlande, Mexique, Norvège, Nouvelle-Zélande]
|
||||
street_address: ['#####', '####', '###']
|
||||
street_suffix: ["de l'Abbaye", "Adolphe Mille", "d'Alésia", "d'Argenteuil", "d'Assas", "du Bac", "de Paris", "La Boétie", "Bonaparte", "de la Bûcherie", "de Caumartin", "Charlemagne", "du Chat-qui-Pêche", "de la Chaussée-d'Antin", "du Dahomey", "Dauphine", "Delesseux", "du Faubourg Saint-Honoré", "du Faubourg-Saint-Denis", "de la Ferronnerie", "des Francs-Bourgeois", "des Grands Augustins", "de la Harpe", "du Havre", "de la Huchette", "Joubert", "Laffitte", "Lepic", "des Lombards", "Marcadet", "Molière", "Monsieur-le-Prince", "de Montmorency", "Montorgueil", "Mouffetard", "de Nesle", "Oberkampf", "de l'Odéon", "d'Orsel", "de la Paix", "des Panoramas", "Pastourelle", "Pierre Charron", "de la Pompe", "de Presbourg", "de Provence", "de Richelieu", "de Rivoli", "des Rosiers", "Royale", "d'Abbeville", "Saint-Honoré", "Saint-Bernard", "Saint-Denis", "Saint-Dominique", "Saint-Jacques", "Saint-Séverin", "des Saussaies", "de Seine", "de Solférino", "Du Sommerard", "de Tilsitt", "Vaneau", "de Vaugirard", "de la Victoire", "Zadkine"]
|
||||
secondary_address: ['Apt. ###', '# étage']
|
||||
postcode: ['#####']
|
||||
state: ['Alsace', 'Aquitaine', 'Auvergne', 'Basse-Normandie', 'Bourgogne', 'Bretagne', 'Centre', 'Champagne-Ardenne', 'Corse', 'Franche-Comté', 'Haute-Normandie', 'Île-de-France', 'Languedoc-Roussillon', 'Limousin', 'Lorraine', 'Midi-Pyrénées', 'Nord-Pas-de-Calais', 'Pays de la Loire', 'Picardie', 'Poitou-Charentes', "Provence-Alpes-Côte d'Azur", 'Rhône-Alpes']
|
||||
state_abbr: [AL, AQ, AU, BN, BO, BR, CE, CH]
|
||||
company:
|
||||
suffix: [SARL, SA, EURL, SAS, SEM, SCOP, GIE, EI]
|
||||
internet:
|
||||
free_email: [gmail.com, yahoo.fr, hotmail.fr]
|
||||
domain_suffix: [com, fr, eu, info, name, net, org]
|
||||
lorem:
|
||||
words: [alias, consequatur, aut, perferendis, sit, voluptatem, accusantium, doloremque, aperiam, eaque, ipsa, quae, ab, illo, inventore, veritatis, et, quasi, architecto, beatae, vitae, dicta, sunt, explicabo, aspernatur, aut, odit, aut, fugit, sed, quia, consequuntur, magni, dolores, eos, qui, ratione, voluptatem, sequi, nesciunt, neque, dolorem, ipsum, quia, dolor, sit, amet, consectetur, adipisci, velit, sed, quia, non, numquam, eius, modi, tempora, incidunt, ut, labore, et, dolore, magnam, aliquam, quaerat, voluptatem, ut, enim, ad, minima, veniam, quis, nostrum, exercitationem, ullam, corporis, nemo, enim, ipsam, voluptatem, quia, voluptas, sit, suscipit, laboriosam, nisi, ut, aliquid, ex, ea, commodi, consequatur, quis, autem, vel, eum, iure, reprehenderit, qui, in, ea, voluptate, velit, esse, quam, nihil, molestiae, et, iusto, odio, dignissimos, ducimus, qui, blanditiis, praesentium, laudantium, totam, rem, voluptatum, deleniti, atque, corrupti, quos, dolores, et, quas, molestias, excepturi, sint, occaecati, cupiditate, non, provident, sed, ut, perspiciatis, unde, omnis, iste, natus, error, similique, sunt, in, culpa, qui, officia, deserunt, mollitia, animi, id, est, laborum, et, dolorum, fuga, et, harum, quidem, rerum, facilis, est, et, expedita, distinctio, nam, libero, tempore, cum, soluta, nobis, est, eligendi, optio, cumque, nihil, impedit, quo, porro, quisquam, est, qui, minus, id, quod, maxime, placeat, facere, possimus, omnis, voluptas, assumenda, est, omnis, dolor, repellendus, temporibus, autem, quibusdam, et, aut, consequatur, vel, illum, qui, dolorem, eum, fugiat, quo, voluptas, nulla, pariatur, at, vero, eos, et, accusamus, officiis, debitis, aut, rerum, necessitatibus, saepe, eveniet, ut, et, voluptates, repudiandae, sint, et, molestiae, non, recusandae, itaque, earum, rerum, hic, tenetur, a, sapiente, delectus, ut, aut, reiciendis, voluptatibus, maiores, doloribus, asperiores, repellat]
|
||||
name:
|
||||
first_name: [Enzo, Lucas, Mathis, Nathan, Thomas, Hugo, Théo, Tom, Louis, Raphaël, Clément, Léo, Mathéo, Maxime, Alexandre, Antoine, Yanis, Paul, Baptiste, Alexis, Gabriel, Arthur, Jules, Ethan, Noah, Quentin, Axel, Evan, Mattéo, Romain, Valentin, Maxence, Noa, Adam, Nicolas, Julien, Mael, Pierre, Rayan, Victor, Mohamed, Adrien, Kylian, Sacha, Benjamin, Léa, Clara, Manon, Chloé, Camille, Ines, Sarah, Jade, Lola, Anaïs, Lucie, Océane, Lilou, Marie, Eva, Romane, Lisa, Zoe, Julie, Mathilde, Louise, Juliette, Clémence, Célia, Laura, Lena, Maëlys, Charlotte, Ambre, Maeva, Pauline, Lina, Jeanne, Lou, Noémie, Justine, Louna, Elisa, Alice, Emilie, Carla, Maëlle, Alicia, Mélissa]
|
||||
last_name: [Martin, Bernard, Dubois, Thomas, Robert, Richard, Petit, Durand, Leroy, Moreau, Simon, Laurent, Lefebvre, Michel, Garcia, David, Bertrand, Roux, Vincent, Fournier, Morel, Girard, Andre, Lefevre, Mercier, Dupont, Lambert, Bonnet, Francois, Martinez, Legrand, Garnier, Faure, Rousseau, Blanc, Guerin, Muller, Henry, Roussel, Nicolas, Perrin, Morin, Mathieu, Clement, Gauthier, Dumont, Lopez, Fontaine, Chevalier, Robin, Masson, Sanchez, Gerard, Nguyen, Boyer, Denis, Lemaire, Duval, Joly, Gautier, Roger, Roche, Roy, Noel, Meyer, Lucas, Meunier, Jean, Perez, Marchand, Dufour, Blanchard, Marie, Barbier, Brun, Dumas, Brunet, Schmitt, Leroux, Colin, Fernandez, Pierre, Renard, Arnaud, Rolland, Caron, Aubert, Giraud, Leclerc, Vidal, Bourgeois, Renaud, Lemoine, Picard, Gaillard, Philippe, Leclercq, Lacroix, Fabre, Dupuis, Olivier, Rodriguez, Da silva, Hubert, Louis, Charles, Guillot, Riviere, Le gall, Guillaume, Adam, Rey, Moulin, Gonzalez, Berger, Lecomte, Menard, Fleury, Deschamps, Carpentier, Julien, Benoit, Paris, Maillard, Marchal, Aubry, Vasseur, Le roux, Renault, Jacquet, Collet, Prevost, Poirier, Charpentier, Royer, Huet, Baron, Dupuy, Pons, Paul, Laine, Carre, Breton, Remy, Schneider, Perrot, Guyot, Barre, Marty, Cousin]
|
||||
prefix: [M, Mme, Mlle, Dr, Prof]
|
||||
suffix: [Jr., Sr., I, II, III, IV, V, MD, DDS, PhD, DVM]
|
||||
formats:
|
||||
-
|
||||
- :prefix
|
||||
- :first_name
|
||||
- :last_name
|
||||
-
|
||||
- :first_name
|
||||
- :last_name
|
||||
- :suffix
|
||||
-
|
||||
- :first_name
|
||||
- :last_name
|
||||
-
|
||||
- :first_name
|
||||
- :last_name
|
||||
-
|
||||
- :first_name
|
||||
- :last_name
|
||||
-
|
||||
- :first_name
|
||||
- :last_name
|
||||
|
||||
phone_number:
|
||||
formats: ['01########', '02########', '03########', '04########', '05########', '06########', '07########', '+33 1########', '+33 2########', '+33 3########', '+33 4########', '+33 5########', '+33 6########', '+33 7########']
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class BothifyTest {
|
||||
private Faker faker = new Faker();
|
||||
|
||||
@Test
|
||||
public void shouldGenerateLettersAndNumbers() {
|
||||
Assert.assertTrue(faker.bothify("????##@gmail.com").matches("\\w{4}\\d{2}@gmail.com"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.runners.Parameterized.*;
|
||||
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class FakerTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FakerTest.class);
|
||||
private Faker faker;
|
||||
|
||||
public FakerTest(Locale locale) {
|
||||
faker = new Faker(locale);
|
||||
}
|
||||
|
||||
@Parameters(name = "testing locale {0}")
|
||||
public static Collection<Object[]> data() {
|
||||
Object[][] data = new Object[][]{{Locale.ENGLISH}, {Locale.FRENCH}};
|
||||
return Arrays.asList(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNames() {
|
||||
String firstName = faker.firstName();
|
||||
logger.info("Test first name: " + firstName);
|
||||
assertNotNull(firstName);
|
||||
|
||||
String lastName = faker.lastName();
|
||||
logger.info("Test last name: " + lastName);
|
||||
assertNotNull(lastName);
|
||||
|
||||
String prefix = faker.prefix();
|
||||
logger.info("Test prefix: " + prefix);
|
||||
assertNotNull(prefix);
|
||||
|
||||
String suffix = faker.suffix();
|
||||
logger.info("Test suffix: " + suffix);
|
||||
assertNotNull(suffix);
|
||||
|
||||
String name = faker.name();
|
||||
logger.info("Test name: " + name);
|
||||
assertNotNull(name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPhoneNumber() {
|
||||
String phoneNumber = faker.phoneNumber();
|
||||
logger.info("Phone number: " + phoneNumber);
|
||||
assertNotNull(phoneNumber);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSpecifiedNumOfWords() {
|
||||
List<String> words = faker.words(4);
|
||||
logger.info("Test words: " + words.toString());
|
||||
assertEquals(4, words.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSentence() {
|
||||
String sentence = faker.sentence(7);
|
||||
logger.info("Test sentence: " + sentence);
|
||||
assertNotNull(sentence);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSentences() {
|
||||
List<String> sentences = faker.sentences(3);
|
||||
logger.info("Test sentences: " + sentences);
|
||||
assertEquals(3, sentences.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecifiedNumOfParagraphs() {
|
||||
String paragraph = faker.paragraph(5);
|
||||
logger.info("Test paragraph: " + paragraph);
|
||||
assertNotNull(paragraph);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreetName() {
|
||||
String streetName = faker.streetName();
|
||||
logger.info("Street name: " + streetName);
|
||||
assertNotNull(streetName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreetAddress() {
|
||||
String streetAddress = faker.streetAddress(true);
|
||||
logger.info("Street address: " + streetAddress);
|
||||
assertNotNull(streetAddress);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondaryAddress() {
|
||||
String secondaryAddress = faker.secondaryAddress();
|
||||
logger.info("Secondary address: " + secondaryAddress);
|
||||
assertNotNull(secondaryAddress);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZipCode() {
|
||||
String zip = faker.zipCode();
|
||||
logger.info("Address zip code: " + zip);
|
||||
assertNotNull(zip);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreetSuffix() {
|
||||
String streetSuffix = faker.streetSuffix();
|
||||
logger.info("Street suffix: " + streetSuffix);
|
||||
assertNotNull(streetSuffix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCitySuffix() {
|
||||
String citySuffix = faker.citySuffix();
|
||||
logger.info("City suffix: " + citySuffix);
|
||||
assertNotNull(citySuffix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCityPrefix() {
|
||||
String cityPrefix = faker.cityPrefix();
|
||||
logger.info("City prefix: " + cityPrefix);
|
||||
assertNotNull(cityPrefix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStateAbbr() {
|
||||
String stateAbbr = faker.stateAbbr();
|
||||
logger.info("State abbr: " + stateAbbr);
|
||||
assertNotNull(stateAbbr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountry() {
|
||||
String country = faker.country();
|
||||
logger.info("Country: " + country);
|
||||
assertNotNull(country);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParagraph() {
|
||||
String paragraph = faker.paragraph();
|
||||
logger.info("Paragraph: " + paragraph);
|
||||
assertNotNull(paragraph);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParagraphs() {
|
||||
final int paragraphCount = 10;
|
||||
List<String> paragraphs = faker.paragraphs(paragraphCount);
|
||||
logger.info("Paragraphs: " + paragraphs);
|
||||
assertEquals(paragraphCount, paragraphs.size());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class WordsTest {
|
||||
private Faker faker = new Faker();
|
||||
|
||||
@Test
|
||||
public void shouldGenerateWordsFromLorem() {
|
||||
assertThat(faker.words(10).get(0), notNullValue());
|
||||
assertThat(faker.words(10).get(9), notNullValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
en:
|
||||
faker:
|
||||
abc:
|
||||
def: [x, y, z]
|
||||
Reference in New Issue
Block a user