Compare commits

..

28 Commits

Author SHA1 Message Date
Ricky aa1735a6b5 made the countyByZipcode test not random 2019-07-20 16:02:48 +10:00
Ricky 469f007d6d removing flakly reg-ex assertion 2019-07-20 12:42:54 +10:00
Ricky Yim 31db0ab659 Update README.md 2019-07-20 12:41:03 +10:00
Ricky Yim 563e0c79df Create CONTRIBUTING.md
Adding
2019-07-20 12:35:12 +10:00
Ricky Yim c0f8d153fe Merge pull request #404 from DiUS/is_string_with_contents
added is string with contents matcher and used it instead of regular …
2019-07-20 12:30:06 +10:00
Ricky d1749e793c added is string with contents matcher and used it instead of regular expression matching as those matches are getting too brittle resulting in too many test failures 2019-07-20 12:21:36 +10:00
Ricky Yim d5ee26d713 Update .travis.yml
Trying to fix issues with jdk11
2019-07-20 11:41:44 +10:00
Ricky Yim 602b8d2ef7 Merge pull request #400 from egoetschalckx/add-country-name
add country name
2019-07-19 22:29:55 +10:00
Ricky Yim d6e647bfd5 Merge pull request #401 from L-Evg/fb_Aviation_Faker
Aviation Faker.
2019-07-19 22:28:52 +10:00
Lozovan Evgeniy a8a1c2687b Aviation Faker. 2019-07-05 19:10:24 +03:00
Eric Goetschalckx 598b00fe7a add country name 2019-07-04 10:26:05 -04:00
Ricky Yim 506d072988 Merge pull request #393 from TOEndacott/master
BackToTheFuture
2019-06-24 09:24:29 +10:00
Tom Endacott 5e7c7c0246 added BTTF to FakerIT 2019-06-19 11:15:16 +01:00
Tom Endacott bdd923612a update BackToTheFutureTest regex to include dash and not comma, remove whitespace BackToTheFuture 2019-06-18 11:23:54 +01:00
Tom Endacott 043ad3edc6 added all functionality for BackToTheFuture 2019-06-18 11:13:00 +01:00
Ricky Yim e6d0aa4a5b Update README.md 2019-05-11 12:56:45 +10:00
Ricky d42f386555 [maven-release-plugin] prepare for next development iteration 2019-05-10 20:25:26 +10:00
Ricky a568d925cc [maven-release-plugin] prepare release javafaker-0.18 2019-05-10 20:25:11 +10:00
Ricky Yim 0eba56018b Merge pull request #375 from srikarn/master
Added support for date expressions like #{date.future '10','TimeUnit.DAYS'}
2019-05-06 00:54:58 +02:00
Ricky Yim aa64edf17c Merge pull request #364 from haruntuncay/master
Add digit constraint for passwords, issue #360
2019-04-26 13:19:45 +02:00
Srikar Nadipally 6a2123b3d7 Added tests for the date expression support 2019-04-23 15:33:20 -05:00
Ricky Yim 81e1f86db2 Merge pull request #370 from haruntuncay/issue#282
Add hex value generation, both for as color and as random, see issue #282
2019-04-17 20:08:47 +10:00
Srikar Nadipally 23fd6e63f9 Added support for date expressions like #{date.future '10','TimeUnit.DAYS'} 2019-04-12 15:03:39 -05:00
Ricky Yim 06ece70248 Merge pull request #374 from DiUS/performance
lazy loading.. to improve performance so faker doesn't load up all YMLs at once
2019-04-12 10:53:49 +10:00
haruntuncay 357d0c4333 Fixed code review requests. 2019-03-25 14:22:02 +03:00
haruntuncay 8b34ad5983 Change hard-coded random integer upper-bound. 2019-03-14 23:23:31 +03:00
haruntuncay 6440b082ec Add hex value generation, both for as color and as random, see issue #282 2019-03-14 23:09:15 +03:00
haruntuncay e2eec2f552 Add digit constraint for passwords, issue #360 2019-02-28 00:30:21 +03:00
30 changed files with 402 additions and 22 deletions
+1
View File
@@ -5,6 +5,7 @@ jdk:
- openjdk7
- openjdk10
- oraclejdk11
sudo: true
script: "mvn verify failsafe:integration-test failsafe:verify"
branches:
except:
+15
View File
@@ -0,0 +1,15 @@
First and foremost thanks to anyone who contributes, very much appreciated.
## Guidelines
- Need to maintain compatibility with Java 1.6 (and Android). Therefore any attempt to migrate to 1.6 JDKs and above will not be merged back in.
- If you add new faker classes like `Address`, `Country`, and `Number` they should be accompanied by a unit test. Where relevant please add more assertions to the `com.github.javafaker.integration.FakerIT` class.
- If you add a new faker class, update the `README.md`.
- Submit a PR with your change and if there are no comments, changes will be merged in
- If you're not sure about the change, raise an issue and have a discussion before spending time coding it up
- Try and make one logical change per PR. That is not make many changes in one PR. Submit multiple PRs instead
## Building
- Should be as easy as running `mvn clean install` on the root directory
+9 -3
View File
@@ -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.17.2</version>
<version>0.18</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.17.2'
implementation 'com.github.javafaker:javafaker:0.18'
}
```
@@ -47,6 +47,11 @@ Javadoc
http://dius.github.io/java-faker/apidocs/index.html
Contributions
-------------
See [CONTRIBUTING.md](https://github.com/DiUS/java-faker/blob/master/CONTRIBUTING.md)
Fakers
-----
* Ancient
@@ -54,6 +59,7 @@ Fakers
* App
* Artist
* Avatar
* Aviation
* Beer
* Book
* Bool
@@ -178,4 +184,4 @@ TODO
LICENSE
-------
Copyright (c) 2018 DiUS Computing Pty Ltd. See the LICENSE file for license rights and limitations.
Copyright (c) 2019 DiUS Computing Pty Ltd. See the LICENSE file for license rights and limitations.
+1 -1
View File
@@ -3,7 +3,7 @@
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<packaging>jar</packaging>
<version>0.17.3-SNAPSHOT</version>
<version>0.19-SNAPSHOT</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.
@@ -0,0 +1,36 @@
package com.github.javafaker;
/**
* Generates aviation related strings.
*/
public class Aviation {
private final Faker faker;
protected Aviation(Faker faker) {
this.faker = faker;
}
/**
* @return some aircraft name/model/make e.g. "An-2".
*/
public String aircraft() {
return faker.fakeValuesService().fetchString("aviation.aircraft");
}
/**
* Returns an airport ICAO code.
* See also: https://en.wikipedia.org/wiki/List_of_airports_by_ICAO_code:_A
*/
public String airport() {
return faker.fakeValuesService().fetchString("aviation.airport");
}
/**
* Provides a METAR weather report.
* Have a look at https://en.wikipedia.org/wiki/METAR
*/
public String METAR() {
return faker.fakeValuesService().fetchString("aviation.metar");
}
}
@@ -0,0 +1,21 @@
package com.github.javafaker;
public class BackToTheFuture {
private final Faker faker;
protected BackToTheFuture(Faker faker) {
this.faker = faker;
}
public String character() {
return faker.resolve("back_to_the_future.characters");
}
public String date() {
return faker.resolve("back_to_the_future.dates");
}
public String quote() {
return faker.resolve("back_to_the_future.quotes");
}
}
@@ -10,4 +10,15 @@ public class Color {
public String name() {
return faker.fakeValuesService().resolve("color.name", this, faker);
}
public String hex() {
return hex(true);
}
public String hex(boolean includeHashSign) {
String hexString = faker.random().hex(6);
if(includeHashSign)
return "#" + hexString;
return hexString;
}
}
@@ -33,4 +33,8 @@ public class Country {
return faker.fakeValuesService().resolve("country.currency_code", this, faker);
}
public String name() {
return faker.fakeValuesService().resolve("country.name", this, faker);
}
}
@@ -20,6 +20,7 @@ public class Faker {
private final App app;
private final Artist artist;
private final Avatar avatar;
private final Aviation aviation;
private final Lorem lorem;
private final Music music;
private final Name name;
@@ -84,6 +85,7 @@ public class Faker {
private final Weather weather;
private final Lebowski lebowski;
private final Medical medical;
private final BackToTheFuture backToTheFuture;
public Faker() {
this(Locale.ENGLISH);
@@ -105,6 +107,7 @@ public class Faker {
this.app = new App(this);
this.artist = new Artist(this);
this.avatar = new Avatar(this);
this.aviation = new Aviation(this);
this.lorem = new Lorem(this);
this.music = new Music(this);
this.name = new Name(this);
@@ -169,6 +172,7 @@ public class Faker {
this.lebowski = new Lebowski(this);
this.medical = new Medical(this);
this.country = new Country(this);
this.backToTheFuture = new BackToTheFuture(this);
}
/**
@@ -309,6 +313,10 @@ public class Faker {
return avatar;
}
public Aviation aviation() {
return aviation;
}
public Music music() {
return music;
}
@@ -557,6 +565,10 @@ public class Faker {
public Country country(){ return country;}
public BackToTheFuture backToTheFuture() {
return backToTheFuture;
}
public String resolve(String key) {
return this.fakeValuesService.resolve(key, this, this);
}
@@ -110,6 +110,10 @@ public class Internet {
return password(8, 16);
}
public String password(boolean includeDigit) {
return password(8, 16, false, false, includeDigit);
}
public String password(int minimumLength, int maximumLength) {
return password(minimumLength, maximumLength, false);
}
@@ -119,15 +123,19 @@ public class Internet {
}
public String password(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial) {
return password(minimumLength, maximumLength, includeUppercase, includeSpecial, true);
}
public String password(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeSpecial, boolean includeDigit) {
if (includeSpecial) {
char[] password = faker.lorem().characters(minimumLength, maximumLength, includeUppercase).toCharArray();
char[] password = faker.lorem().characters(minimumLength, maximumLength, includeUppercase, includeDigit).toCharArray();
char[] special = new char[]{'!', '@', '#', '$', '%', '^', '&', '*'};
for (int i = 0; i < faker.random().nextInt(minimumLength); i++) {
password[faker.random().nextInt(password.length)] = special[faker.random().nextInt(special.length)];
}
return new String(password);
} else {
return faker.lorem().characters(minimumLength, maximumLength, includeUppercase);
return faker.lorem().characters(minimumLength, maximumLength, includeUppercase, includeDigit);
}
}
+21 -4
View File
@@ -39,17 +39,32 @@ public class Lorem {
return characters(faker.random().nextInt(maximumLength - minimumLength) + minimumLength, includeUppercase);
}
public String characters(int minimumLength, int maximumLength, boolean includeUppercase, boolean includeDigit) {
return characters(faker.random().nextInt(maximumLength - minimumLength) + minimumLength, includeUppercase, includeDigit);
}
public String characters(int fixedNumberOfCharacters) {
return characters(fixedNumberOfCharacters, false);
}
public String characters(int fixedNumberOfCharacters, boolean includeUppercase) {
return characters(fixedNumberOfCharacters, includeUppercase, true);
}
public String characters(int fixedNumberOfCharacters, boolean includeUppercase, boolean includeDigit) {
if (fixedNumberOfCharacters < 1) {
return "";
}
char[] buffer = new char[fixedNumberOfCharacters];
for (int i = 0; i < buffer.length; i++) {
char randomCharacter = characters[faker.random().nextInt(characters.length)];
char randomCharacter;
if (includeDigit) {
randomCharacter = characters[faker.random().nextInt(characters.length)];
} else {
randomCharacter = letters[faker.random().nextInt(letters.length)];
}
if (includeUppercase && faker.bool().bool()) {
randomCharacter = Character.toUpperCase(randomCharacter);
}
@@ -145,15 +160,17 @@ public class Lorem {
static {
StringBuilder builder = new StringBuilder(36);
for (char number = '0'; number <= '9'; number++) {
builder.append(number);
}
for (char character = 'a'; character <= 'z'; character++) {
builder.append(character);
}
letters = builder.toString().toCharArray();
for (char number = '0'; number <= '9'; number++) {
builder.append(number);
}
characters = builder.toString().toCharArray();
}
private static final char[] letters;
private static final char[] characters;
}
@@ -546,10 +546,16 @@ public class FakeValuesService {
Class<?> toType = ClassUtils.primitiveToWrapper(accessor.getParameterTypes()[i]);
try {
final Constructor<?> ctor = toType.getConstructor(String.class);
final Object coercedArgument = ctor.newInstance(args.get(i));
coerced.add(coercedArgument);
if (toType.isEnum()) {
Method method = toType.getMethod( "valueOf", String.class );
String enumArg = args.get( i ).substring( args.get( i ).indexOf( "." ) + 1 );
Object coercedArg = method.invoke( null, enumArg );
coerced.add( coercedArg );
} else {
final Constructor<?> ctor = toType.getConstructor(String.class);
final Object coercedArgument = ctor.newInstance(args.get(i));
coerced.add(coercedArgument);
}
} catch (Exception e) {
log.fine("Unable to coerce " + args.get(i) + " to " + toType.getSimpleName() + " via " + toType.getSimpleName() + "(String) constructor.");
return null;
@@ -54,4 +54,17 @@ public class RandomService {
public Integer nextInt(int min, int max) {
return random.nextInt((max - min) + 1) + min;
}
public String hex() {
return hex(8);
}
public String hex(int length) {
char[] hexValues = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuilder hexString = new StringBuilder();
for(int i = 0; i < length; i++) {
hexString.append(hexValues[nextInt(hexValues.length)]);
}
return hexString.toString();
}
}
@@ -33,6 +33,7 @@ public class EnFile {
"appliance.yml",
"aqua_teen_hunger_force.yml",
"artist.yml",
"aviation.yml",
"back_to_the_future.yml",
"bank.yml",
"beer.yml",
+45
View File
@@ -0,0 +1,45 @@
en:
faker:
aviation:
aircraft: ["An-2", "An-3", "An-8", "An-10", "An-12", "An-24", "An-26", "An-32", "An-38", "An-70", "An-72", "An-74TK", "An-124", "An-225", "Tu-2", "Tu-4", "Tu-16", "Tu-95", "Tu-104", "Tu-114", "Tu-128", "Tu-134", "Tu-144", "Tu-154", "Tu-154M", "Tu-160", "Tu-204", "Tu-214", "Tu-334", "Il-2", "Il-4", "DB-3", "Il-28","Il-38", "Il-76", "Il-86", "Il-96", "Il-112", "Il-114", "Li-2", "Yak-1", "Yak-3", "Yak-9", "Yak-12", "Yak-18A", "Yak-18T", "Yak-52", "Yak-55", "Yak-36", "Yak-38", "Yak-130", "Yak-141", "Yak-152", "Su-2", "Su-7", "Su-7B", "Su-15", "Su-17", "Su-20", "Su-22", "Su-24", "Su-25", "Su-26", "Su-27", "Su-29", "Su-30", "Su-30MK", "Su-30MKI", "Su-32FN", "Su-34", "Su-35", "Su-37", "Su-57", "MiG-1", "MiG-3", "MiG-9", "MiG-15", "MiG-17", "MiG-19", "MiG-21", "MiG-23", "MiG-25", "MiG-29", "MiG-35", "LaGG-3", "La-5", "La-5FN", "La-7", "La-9", "Be-12", "Be-200", "VVA-14", "Cessna-172", "Cessna-182", "Cessna-152", "Cessna-120", "Cessna-140", "Cessna-208", "Mi-8", "Mi-24", "Mi-35", "Mi-17", "Mi-28", "Ka-25", "Ka-27", "Ka-50", "Ka-52", "Po-2", "U-2", "SSJ", "MS-21", "Airbus 300", "Airbus 319", "Airbus 320", "Airbus 321", "Airbus 330", "Airbus 340", "Airbus 350", "Airbus 380", "Boeing 707", "Boeing 727", "Boeing 737", "Boeing 747", "Boeing 757", "Boeing 767", "Boeing 777", "Boeing 787", "C-47", "C-130", "de Havilland Canada DHC-2 Beaver", "de Havilland Canada DHC-6 Twin Otter", "de Havilland Comet", "de Havilland Dragon", "de Havilland Sea Venom", "Piper PA-28 Cherokee", "Piper J-3 Cub", "L-410", "L-29", "L-39", "Zenith STOL CH 701", "Zenair CH 640", "Zmaj Fizir FN", "Zlín Z-50", "Beechcraft Baron", "Beechcraft Queen Air", "Saab 35 Draken", "Saab JAS 39 Gripen", "Dassault Rafale", "Dassault Mirage F1", "Dassault Mirage III", "T-38", "F-4", "F-104", "F-5", "F-105", "F-101", "F-111", "F-15", "F-16", "F-18", "F-117", "F-22", "F-35", "PC-21", "P-39", "P-40", "P-63", "A-5", "A-7", "A-9", "B-25", "B-12", "B-2", "B-52", "Catalina", "Ju-87", "Ju-88", "He-111", "Fw-190", "Bf-109", "Bf-110", "Spitfire", "Hurricane", "Harrier", "Tornado"]
airport: ["AGAF", "AGAT", "AYLA", "AYKY", "BGGD", "ULAA", "BIIS", "UEEE", "URWW", "SGAS", "SBSP", "SVMI", "SCRM", "VABB", "ZSPD", "YPPH", "KSFO", "MMLT", "UWKI", "UWWW", "UUBB", "UUOO", "USRR", "USDB", "UELL", "BIBA", "BIPA", "CYAB", "CYBA", "CYKA", "DAAD", "DIBU", "EBAW", "EBBR", "EBCI", "EBKT", "EBLG", "EBOS", "ELLZ", "ELUS", "ENAL", "ENAN", "ENAS", "FAMG", "FAMO", "FAPA", "FAPH", "FAPG", "FAMW", "GANR", "GCLA", "GCHI", "GASK", "GAYE", "GBYD", "GCFV", "HADD", "HADR", "KAAA", "KAPA", "LBIA", "LBPD", "LBPS", "MHAM", "MHCA", "MHCC", "MHCG", "NFCI", "NFCS", "NFFA", "OIBB", "OIAW", "OIAJ", "OIAA", "PAAK", "PAAL", "PAAM", "PAAN", "RJAA", "RJAF", "SAAC", "SAAG", "SAAJ", "TDCF", "TDPD", "TFFA", "VEAP", "VEBT", "VEAB", "VEAN", "WA44", "WAAA", "WAAB", "YABA", "YAGD", "YALA", "ZBAA", "ZBAD", "ZBAL", "ZBAR", "ZBBB", "RJAH"]
metar: ["METAR: ULAA 011400Z 17004MPS 120V220 9999 SCT030 18/06 Q1002 R08/190068 NOSIG RMK QFE750/1001",
"METAR: BIIS 101100Z 05007KT 9999 FEW025 07/M01 Q1018",
"METAR: UEEE 151700Z 18003MPS CAVOK 19/11 Q1006 R23L/09//60 NOSIG RMK QFE746",
"METAR: URWW 230800Z 02007MPS 9999 BKN050CB 21/08 Q1010 R06/010070 TEMPO -TSRA BKN030CB",
"METAR: VABB 302100Z 02007KT 2100 -RA SCT010 SCT015 FEW030CB OVC080 26/25 Q1002 TEMPO 1500 +RA",
"METAR: ZSPD 311400Z 12002MPS 080V190 9999 -SHRA NSC 23/22 Q1008 NOSIG",
"METAR: YPPH 011730Z 01004KT CAVOK 09/08 Q1021 NOSIG",
"METAR: KSFO 011356Z 25007KT 10SM FEW008 SCT013 SCT200 13/11 A3006 RMK AO2 SLP180 T01330106",
"METAR: MMLT 031340Z 16006KT 8SM FEW040 SCT100 28/26 A2984 RMK 8/130 HZY",
"METAR: NTAA 140330Z 11004KT 9999 FEW023 SCT300 22/17 Q1014 NOSIG",
"METAR: NCRG 130400Z AUTO 10011G23KT 070V160 9999 -RA FEW012/// SCT021/// BKN043/// 20/17 Q1020",
"METAR: PTSA 120350Z 25009KT 10SM SCT022 SCT130 BKN300 31/25 A2976 RMK LAST",
"METAR: YSSY 110700Z 14009KT 9999 VCSH FEW018 SCT022 BKN034 14/13 Q1035 NOSIG",
"METAR: AGGH 102330Z 11002KT 9999 FEW014 23/23 Q1011",
"METAR: WSSS 092200Z 15008KT 130V190 9999 FEW020 BKN300 29/24 Q1009 NOSIG",
"METAR: UIAA 082000Z AUTO 32002MPS 9999 NCD 16/10 Q1009 RMK QFE698/0931",
"METAR: ZSPD 071300Z 13004MPS CAVOK 23/22 Q1001 NOSIG",
"METAR: ZYHB 061600Z 20002MPS 4000 BR SCT033 23/20 Q0999 BECMG TL1420 23008MPS -TSRA",
"METAR: VVNB 310100Z 13008KT 9999 FEW030 32/25 Q1000 NOSIG",
"METAR: OIII 300500Z 18006KT CAVOK 38/02 Q1006 A2973 NOSIG",
"METAR: VNKT 291250Z 36004KT 7000 FEW010 SCT030 BKN100 25/22 Q1003 NOSIG",
"METAR: ZGKL 280600Z 32002MPS 290V350 9999 SCT043 OVC066 26/25 Q1002 RERA NOSIG",
"METAR: UAAA 271730Z 03003MPS 9999 FEW050 30/10 Q1007 R88/CLRD65 NOSIG",
"METAR: HECA 261900Z 34008KT CAVOK 33/17 Q1007 NOSIG",
"METAR: GOOY 251100Z 24008KT 9999 BKN011 27/22 Q1014",
"METAR: OSDI 241330Z 20012KT CAVOK 37/07 Q1006",
"METAR: ORBI 231400Z 30016KT CAVOK 45/08 Q0997 NOSIG",
"METAR: DAAG 221300Z 02012KT 360V070 6000 FEW026 SCT200 34/24 Q1015",
"METAR: DNIB 210500Z 26004KT 9999 SCT009 24/23 Q1013",
"METAR: FKYS 202140Z 26005KT 230V300 9999 BKN013 26/22 Q1018 BECMG BKN016",
"METAR: FACT 190900Z 01008KT 340V050 CAVOK 17/08 Q1024 NOSIG",
"METAR: DIAP 181230Z 22009KT 8000 SCT012 BKN040 27/24 Q1014 TEMPO BKN012",
"METAR: SCRM 171300Z 34008KT 0100 FZFG OVC003 M03/M03 Q1006",
"METAR: SBSP 161800Z 18008KT 4000 -RA BKN007 SCT015 OVC100 13/11 Q1019",
"METAR: SVMI 151204Z 14003KT 9999 SCT016 26/23 Q1013",
"METAR: SCIP 011500Z 33009KT 9999 SCT020 20/17 Q1016 NOSIG",
"METAR: SKBO 021200Z 05007KT 9999 FEW020 SCT200 11/08 A3037 NOSIG",
"METAR: SGAS 031230Z 19007KT 130V220 CAVOK 11/03 Q1028",
"METAR: MMCU 041040Z 00000KT 10SM SCT030 BKN080 BKN200 20/15 A3016 RMK 8/572 RTS",
"METAR: MMTJ 051141Z 00000KT 5SM OVC013 16/14 A3000 RMK SLP161 54000 918 8/5// HZY"]
+3
View File
@@ -78,3 +78,6 @@ ru:
temperature:
celsius: °C
fahrenheit: °F
aviation:
aircraft: ["Aн-2", "Aн-3", "Ан-8", "Ан-10", "Ан-12", "Ан-24", "Ан-26", "Ан-32", "Ан-38", "Ан-70", "Ан-72", "Ан-74TK", "Ан-124", "Ан-225", "Ту-2", "Ту-4", "Ту-16", "Ту-95", "Ту-104", "Ту-114", "Ту-128", "Ту-134", "Ту-144", "Ту-154", "Ту-154M", "Ту-160", "Ту-204", "Ту-214", "Ту-334", "Ил-2", "Ил-4", "ДБ-3", "Ил-28","Ил-38", "Ил-76", "Ил-86", "Ил-96", "Ил-112", "Ил-114", "Ли-2", "Як-1", "Як-3", "Як-9", "Як-12", "Як-18A", "Як-18T", "Як-52", "Як-55", "Як-36", "Як-38", "Як-130", "Як-141", "Як-152", "Су-2", "Су-7", "Су-7B", "Су-15", "Су-17", "Су-20", "Су-22", "Су-24", "Су-25", "Су-26", "Су-27", "Су-29", "Су-30", "Су-30MK", "Су-30MKI", "Су-32FN", "Су-34", "Су-35", "Су-37", "Су-57", "МиГ-1", "МиГ-3", "МиГ-9", "МиГ-15", "МиГ-17", "МиГ-19", "МиГ-21", "МиГ-23", "МиГ-25", "МиГ-29", "МиГ-35", "ЛАГГ-3", "Ла-5", "Ла-5FN", "Ла-7", "Ла-9", "Бе-12", "Бе-200", "ВВА-14", "Цессна-172", "Цессна-182", "Цессна-152", "Цессна-120", "Цессна-140", "Цессна-208", "Ми-8", "Ми-24", "Ми-35", "Ми-17", "Ми-28", "Ка-25", "Ка-27", "Ка-50", "Ка-52", "По-2", "У-2", "SSJ", "МС-21", "Аэробус 300", "Аэробус 319", "Аэробус 320", "Аэробус 321", "Аэробус 330", "Аэробус 340", "Аэробус 350", "Аэробус 380", "Боинг 707", "Боинг 727", "Боинг 737", "Боинг 747", "Боинг 757", "Боинг 767", "Боинг 777", "Боинг 787", "C-47", "C-130", "de Havilland Canada DHC-2 Beaver", "de Havilland Canada DHC-6 Twin Otter", "de Havilland Comet", "de Havilland Dragon", "de Havilland Sea Venom", "Piper PA-28 Cherokee", "Piper J-3 Cub", "L-410", "L-29", "L-39", "Zenith STOL CH 701", "Zenair CH 640", "Zmaj Fizir FN", "Zlín Z-50", "Beechcraft Baron", "Beechcraft Queen Air", "Saab 35 Draken", "Saab JAS 39 Gripen", "Dassault Rafale", "Dassault Mirage F1", "Dassault Mirage III", "T-38", "Ф-4", "Ф-104", "Ф-5", "Ф-105", "Ф-101", "Ф-111", "Ф-15", "Ф-16", "Ф-18", "Ф-117", "Ф-22", "Ф-35", "PC-21", "P-39", "P-40", "P-63", "A-5", "A-7", "A-9", "Б-25", "Б-2", "Б-52", "Каталина", "Ю-52", "Ю-87", "Ю-88", "Хе-111", "Фв-190", "Ме-109", "Ме-110", "Спитфаер", "Харрикейн", "Харриер", "Торнадо"]
@@ -22,7 +22,6 @@ public class AbstractFakerTest {
@Before
public void before() {
MockitoAnnotations.initMocks(this);
Logger rootLogger = LogManager.getLogManager().getLogger("");
Handler[] handlers = rootLogger.getHandlers();
@@ -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,17 @@
package com.github.javafaker;
import com.github.javafaker.repeating.Repeat;
import org.junit.Test;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static org.junit.Assert.assertThat;
public class AviationTest extends AbstractFakerTest {
@Test
@Repeat(times=3)
public void testAviation() {
String airport = faker.aviation().airport();
assertThat(airport, matchesRegularExpression("\\w{4}"));
}
}
@@ -0,0 +1,25 @@
package com.github.javafaker;
import org.junit.Test;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static com.github.javafaker.matchers.IsStringWithContents.isStringWithContents;
import static org.junit.Assert.assertThat;
public class BackToTheFutureTest extends AbstractFakerTest {
@Test
public void character() {
assertThat(faker.backToTheFuture().character(), isStringWithContents());
}
@Test
public void date() {
assertThat(faker.backToTheFuture().date(), matchesRegularExpression("([A-za-z]{3,8}) ([1-9]|[1-2]\\d|3[0-1]), (18[8-9]\\d|19[0-9]\\d|200\\d|201[0-5])"));
}
@Test
public void quote() {
assertThat(faker.backToTheFuture().quote(), isStringWithContents());
}
}
@@ -11,4 +11,14 @@ public class ColorTest extends AbstractFakerTest {
public void testName() {
assertThat(faker.color().name(), matchesRegularExpression("(\\w+ ?){1,2}"));
}
@Test
public void testHex() {
assertThat(faker.color().hex(), matchesRegularExpression("^#[0-9A-F]{6}$"));
}
@Test
public void testHexNoHashSign() {
assertThat(faker.color().hex(false), matchesRegularExpression("^[0-9A-F]{6}$"));
}
}
@@ -3,6 +3,7 @@ package com.github.javafaker;
import com.github.javafaker.repeating.Repeat;
import org.junit.Test;
import static com.github.javafaker.matchers.IsStringWithContents.isStringWithContents;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static org.junit.Assert.assertThat;
@@ -40,4 +41,9 @@ public class CountryTest extends AbstractFakerTest {
public void testCurrencyCode() {
assertThat(faker.country().currencyCode(), matchesRegularExpression("([\\w-]+ ?)+"));
}
@Test
public void testName() {
assertThat(faker.country().name(), isStringWithContents());
}
}
@@ -124,6 +124,12 @@ public class InternetTest extends AbstractFakerTest {
assertThat(faker.internet().password(), matchesRegularExpression("[a-z\\d]{8,16}"));
}
@Test
public void testPasswordIncludeDigit() {
assertThat(faker.internet().password(), matchesRegularExpression("[a-z\\d]{8,16}"));
assertThat(faker.internet().password(false), matchesRegularExpression("[a-z]{8,16}"));
}
@Test
public void testPasswordMinLengthMaxLength() {
assertThat(faker.internet().password(10, 25), matchesRegularExpression("[a-z\\d]{10,25}"));
@@ -142,6 +148,14 @@ public class InternetTest extends AbstractFakerTest {
assertThat(faker.internet().password(10, 25, true, true), matchesRegularExpression("[a-zA-Z\\d!@#$%^&*]{10,25}"));
}
@Test
public void testPasswordMinLengthMaxLengthIncludeUpperCaseIncludeSpecialIncludeDigit() {
assertThat(faker.internet().password(10, 25, false, false, false), matchesRegularExpression("[a-z]{10,25}"));
assertThat(faker.internet().password(10, 25, false, true, true), matchesRegularExpression("[a-z\\d!@#$%^&*]{10,25}"));
assertThat(faker.internet().password(10, 25, true, true, false), matchesRegularExpression("[a-zA-Z!@#$%^&*]{10,25}"));
assertThat(faker.internet().password(10, 25, true, true, true), matchesRegularExpression("[a-zA-Z\\d!@#$%^&*]{10,25}"));
}
@Test
public void testMacAddress() {
assertThat(faker.internet().macAddress(), countOf(':', is(5)));
@@ -74,6 +74,12 @@ public class LoremTest extends AbstractFakerTest {
assertThat(faker.lorem().characters(1, 10), matchesRegularExpression("[a-zA-Z\\d]{1,10}"));
}
@Test
public void testCharactersMinimumMaximumLengthIncludeUppercaseIncludeDigit() {
assertThat(faker.lorem().characters(1, 10, false, false), matchesRegularExpression("[a-zA-Z]{1,10}"));
assertThat(faker.lorem().characters(1, 10, true, true), matchesRegularExpression("[a-zA-Z\\d]{1,10}"));
}
@Test
public void testSentence() {
assertThat(faker.lorem().sentence(), matchesRegularExpression("(\\w+\\s?){4,10}\\."));
@@ -1,31 +1,30 @@
package com.github.javafaker;
import com.github.javafaker.repeating.Repeat;
import org.junit.Test;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static com.github.javafaker.matchers.IsStringWithContents.isStringWithContents;
import static org.junit.Assert.assertThat;
public class MedicalTest extends AbstractFakerTest {
@Test
public void testMedicineName() {
assertThat(faker.medical().medicineName(), matchesRegularExpression("([\\w']+\\.?( )?){2,5}"));
assertThat(faker.medical().medicineName(), isStringWithContents());
}
@Test
public void testDiseaseName() {
assertThat(faker.medical().diseaseName(), matchesRegularExpression("([\\w']+\\.?( )?){2,8}"));
assertThat(faker.medical().diseaseName(), isStringWithContents());
}
@Test
public void testHospitalName() {
assertThat(faker.medical().hospitalName(), matchesRegularExpression("[A-Z ,./&'()]+"));
assertThat(faker.medical().hospitalName(), isStringWithContents());
}
@Test
public void testSymptom() {
assertThat(faker.medical().symptoms(), matchesRegularExpression("[\\w'\\s\\(\\)]+"));
assertThat(faker.medical().symptoms(), isStringWithContents());
}
@@ -94,6 +94,8 @@ public class FakerIT {
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.address());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.app());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.artist());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.aviation());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.backToTheFuture());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.business());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.book());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.chuckNorris());
@@ -0,0 +1,28 @@
package com.github.javafaker.matchers;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
public class IsStringWithContents extends TypeSafeMatcher<String> {
@Override
protected boolean matchesSafely(String s) {
if (s == null) return false;
return s.trim().length() > 0;
}
@Override
public void describeTo(Description description) {
description.appendText("is string with contents");
}
@Factory
public static <T> Matcher<String> isStringWithContents() {
return new IsStringWithContents();
}
}
@@ -0,0 +1,37 @@
package com.github.javafaker.matchers;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
public class IsStringWithContentsTest {
private IsStringWithContents matcher;
@Before
public void before() {
matcher = new IsStringWithContents();
}
@Test
public void emptyStringShouldFail() {
assertThat(matcher.matchesSafely(""), is(false));
}
@Test
public void nullStringShouldFail() {
assertThat(matcher.matchesSafely(null), is(false));
}
@Test
public void stringShouldPass() {
assertThat(matcher.matchesSafely("123"), is(true));
}
@Test
public void whiteSpaceShouldFail() {
assertThat(matcher.matchesSafely(" "), is(false));
}
}
@@ -10,7 +10,10 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@@ -22,6 +25,9 @@ import static org.mockito.Mockito.*;
public class FakeValuesServiceTest extends AbstractFakerTest {
private static final Long MILLIS_IN_AN_HOUR = 1000 * 60 * 60L;
private static final Long MILLIS_IN_A_DAY = MILLIS_IN_AN_HOUR * 24;
@Mock
private RandomService randomService;
@@ -226,6 +232,32 @@ public class FakeValuesServiceTest extends AbstractFakerTest {
"Unable to resolve #{Number.number_between 'x','y'} directive.");
}
@Test
public void futureDateExpression() throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE MMM dd HH:mm:ss z yyyy" );
Date now = new Date();
Date nowPlus10Days = new Date( now.getTime() + MILLIS_IN_A_DAY * 10 );
Date date = dateFormat.parse( fakeValuesService.expression( "#{date.future '10','TimeUnit.DAYS'}", faker ));
assertThat( date.getTime(), greaterThan( now.getTime() ));
assertThat( date.getTime(), lessThan( nowPlus10Days.getTime() ));
}
@Test
public void pastDateExpression() throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat( "EEE MMM dd HH:mm:ss z yyyy" );
Date now = new Date();
Date nowMinus5Hours = new Date( now.getTime() - MILLIS_IN_AN_HOUR * 5 );
Date date = dateFormat.parse( fakeValuesService.expression( "#{date.past '5','TimeUnit.HOURS'}", faker ));
assertThat( date.getTime(), greaterThan( nowMinus5Hours.getTime() ));
assertThat( date.getTime(), lessThan( now.getTime() ));
}
/**
* Two things are important here:
* 1) the message in the exception should be USEFUL
@@ -9,6 +9,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Random;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.CombinableMatcher.both;
@@ -62,4 +63,9 @@ public class RandomServiceTest extends AbstractFakerTest {
assertThat(randomService.nextInt(-5, 5), both(lessThanOrEqualTo(5)).and(greaterThanOrEqualTo(-5)));
}
}
@Test
public void testHex() {
assertThat(randomService.hex(8), matchesRegularExpression("^[0-9A-F]{8}$"));
}
}