From 598b00fe7a85e652283534d8209c4ade308cbbbc Mon Sep 17 00:00:00 2001 From: Eric Goetschalckx Date: Thu, 4 Jul 2019 10:26:05 -0400 Subject: [PATCH 01/12] add country name --- src/main/java/com/github/javafaker/Country.java | 4 ++++ src/test/java/com/github/javafaker/CountryTest.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/github/javafaker/Country.java b/src/main/java/com/github/javafaker/Country.java index 6d0037b3..416d952d 100644 --- a/src/main/java/com/github/javafaker/Country.java +++ b/src/main/java/com/github/javafaker/Country.java @@ -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); + } + } diff --git a/src/test/java/com/github/javafaker/CountryTest.java b/src/test/java/com/github/javafaker/CountryTest.java index 8211f302..74e442c3 100644 --- a/src/test/java/com/github/javafaker/CountryTest.java +++ b/src/test/java/com/github/javafaker/CountryTest.java @@ -40,4 +40,9 @@ public class CountryTest extends AbstractFakerTest { public void testCurrencyCode() { assertThat(faker.country().currencyCode(), matchesRegularExpression("([\\w-]+ ?)+")); } + + @Test + public void testName() { + assertThat(faker.country().name(), matchesRegularExpression("([\\w-]+ ?)+")); + } } From a8a1c2687bf6ba8e379180e0ef52272b11f87a9e Mon Sep 17 00:00:00 2001 From: Lozovan Evgeniy Date: Fri, 5 Jul 2019 19:10:24 +0300 Subject: [PATCH 02/12] Aviation Faker. --- README.md | 1 + .../java/com/github/javafaker/Aviation.java | 36 +++++++++++++++ src/main/java/com/github/javafaker/Faker.java | 6 +++ .../javafaker/service/files/EnFile.java | 1 + src/main/resources/en/aviation.yml | 45 +++++++++++++++++++ src/main/resources/ru.yml | 3 ++ .../com/github/javafaker/AviationTest.java | 17 +++++++ .../github/javafaker/integration/FakerIT.java | 1 + 8 files changed, 110 insertions(+) create mode 100644 src/main/java/com/github/javafaker/Aviation.java create mode 100644 src/main/resources/en/aviation.yml create mode 100644 src/test/java/com/github/javafaker/AviationTest.java diff --git a/README.md b/README.md index 38f880a5..1c243043 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Fakers * App * Artist * Avatar +* Aviation * Beer * Book * Bool diff --git a/src/main/java/com/github/javafaker/Aviation.java b/src/main/java/com/github/javafaker/Aviation.java new file mode 100644 index 00000000..5eb3c046 --- /dev/null +++ b/src/main/java/com/github/javafaker/Aviation.java @@ -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"); + } +} \ No newline at end of file diff --git a/src/main/java/com/github/javafaker/Faker.java b/src/main/java/com/github/javafaker/Faker.java index ef2fd6de..e07257ac 100644 --- a/src/main/java/com/github/javafaker/Faker.java +++ b/src/main/java/com/github/javafaker/Faker.java @@ -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; @@ -106,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); @@ -311,6 +313,10 @@ public class Faker { return avatar; } + public Aviation aviation() { + return aviation; + } + public Music music() { return music; } diff --git a/src/main/java/com/github/javafaker/service/files/EnFile.java b/src/main/java/com/github/javafaker/service/files/EnFile.java index 7dbf6b83..44532b74 100644 --- a/src/main/java/com/github/javafaker/service/files/EnFile.java +++ b/src/main/java/com/github/javafaker/service/files/EnFile.java @@ -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", diff --git a/src/main/resources/en/aviation.yml b/src/main/resources/en/aviation.yml new file mode 100644 index 00000000..d983573d --- /dev/null +++ b/src/main/resources/en/aviation.yml @@ -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"] \ No newline at end of file diff --git a/src/main/resources/ru.yml b/src/main/resources/ru.yml index def38233..4864cd28 100644 --- a/src/main/resources/ru.yml +++ b/src/main/resources/ru.yml @@ -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", "Спитфаер", "Харрикейн", "Харриер", "Торнадо"] diff --git a/src/test/java/com/github/javafaker/AviationTest.java b/src/test/java/com/github/javafaker/AviationTest.java new file mode 100644 index 00000000..dc08f623 --- /dev/null +++ b/src/test/java/com/github/javafaker/AviationTest.java @@ -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}")); + } +} \ No newline at end of file diff --git a/src/test/java/com/github/javafaker/integration/FakerIT.java b/src/test/java/com/github/javafaker/integration/FakerIT.java index a52a39ac..364ab5f4 100644 --- a/src/test/java/com/github/javafaker/integration/FakerIT.java +++ b/src/test/java/com/github/javafaker/integration/FakerIT.java @@ -94,6 +94,7 @@ public class FakerIT { testAllMethodsThatReturnStringsActuallyReturnStrings(faker.address()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.app()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.artist()); + testAllMethodsThatReturnStringsActuallyReturnStrings(faker.aviation()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.backToTheFuture()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.business()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.book()); From d5ee26d7131edc95fc36c14b8c997b5ef8935f34 Mon Sep 17 00:00:00 2001 From: Ricky Yim Date: Sat, 20 Jul 2019 11:41:44 +1000 Subject: [PATCH 03/12] Update .travis.yml Trying to fix issues with jdk11 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a0f9abfa..e0ffb7c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ jdk: - openjdk7 - openjdk10 - oraclejdk11 +sudo: true script: "mvn verify failsafe:integration-test failsafe:verify" branches: except: From d1749e793ced1a95e08981be25c113304fc38067 Mon Sep 17 00:00:00 2001 From: Ricky Date: Sat, 20 Jul 2019 12:21:36 +1000 Subject: [PATCH 04/12] 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 --- .../github/javafaker/AbstractFakerTest.java | 1 - .../github/javafaker/BackToTheFutureTest.java | 7 ++-- .../com/github/javafaker/MedicalTest.java | 11 +++--- .../matchers/IsStringWithContents.java | 28 ++++++++++++++ .../matchers/IsStringWithContentsTest.java | 37 +++++++++++++++++++ 5 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 src/test/java/com/github/javafaker/matchers/IsStringWithContents.java create mode 100644 src/test/java/com/github/javafaker/matchers/IsStringWithContentsTest.java diff --git a/src/test/java/com/github/javafaker/AbstractFakerTest.java b/src/test/java/com/github/javafaker/AbstractFakerTest.java index 9dd9b5e3..fb4621f5 100644 --- a/src/test/java/com/github/javafaker/AbstractFakerTest.java +++ b/src/test/java/com/github/javafaker/AbstractFakerTest.java @@ -22,7 +22,6 @@ public class AbstractFakerTest { @Before public void before() { MockitoAnnotations.initMocks(this); - Logger rootLogger = LogManager.getLogManager().getLogger(""); Handler[] handlers = rootLogger.getHandlers(); diff --git a/src/test/java/com/github/javafaker/BackToTheFutureTest.java b/src/test/java/com/github/javafaker/BackToTheFutureTest.java index c6bb1c9f..d28b2239 100644 --- a/src/test/java/com/github/javafaker/BackToTheFutureTest.java +++ b/src/test/java/com/github/javafaker/BackToTheFutureTest.java @@ -3,15 +3,14 @@ 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 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(), matchesRegularExpression("[A-Za-z .-]+")); + assertThat(faker.backToTheFuture().character(), isStringWithContents()); } @Test @@ -21,6 +20,6 @@ public class BackToTheFutureTest extends AbstractFakerTest { @Test public void quote() { - assertThat(faker.backToTheFuture().quote(), not(isEmptyOrNullString())); + assertThat(faker.backToTheFuture().quote(), isStringWithContents()); } } diff --git a/src/test/java/com/github/javafaker/MedicalTest.java b/src/test/java/com/github/javafaker/MedicalTest.java index 9a5d8093..4efde2c3 100644 --- a/src/test/java/com/github/javafaker/MedicalTest.java +++ b/src/test/java/com/github/javafaker/MedicalTest.java @@ -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()); } diff --git a/src/test/java/com/github/javafaker/matchers/IsStringWithContents.java b/src/test/java/com/github/javafaker/matchers/IsStringWithContents.java new file mode 100644 index 00000000..625de955 --- /dev/null +++ b/src/test/java/com/github/javafaker/matchers/IsStringWithContents.java @@ -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 { + + @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 Matcher isStringWithContents() { + return new IsStringWithContents(); + } + +} diff --git a/src/test/java/com/github/javafaker/matchers/IsStringWithContentsTest.java b/src/test/java/com/github/javafaker/matchers/IsStringWithContentsTest.java new file mode 100644 index 00000000..c437ce94 --- /dev/null +++ b/src/test/java/com/github/javafaker/matchers/IsStringWithContentsTest.java @@ -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)); + } +} From 563e0c79dfd4f4dafe2d3c6b34f8b336e3c0705d Mon Sep 17 00:00:00 2001 From: Ricky Yim Date: Sat, 20 Jul 2019 12:35:12 +1000 Subject: [PATCH 05/12] Create CONTRIBUTING.md Adding --- CONTRIBUTING.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..74e64228 --- /dev/null +++ b/CONTRIBUTING.md @@ -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 From 31db0ab65927376bd0bf5738582947fdebadc7dd Mon Sep 17 00:00:00 2001 From: Ricky Yim Date: Sat, 20 Jul 2019 12:41:03 +1000 Subject: [PATCH 06/12] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 1c243043..01cc4f81 100644 --- a/README.md +++ b/README.md @@ -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 From 469f007d6dc183e62b24c4b6292fe194926fd8c8 Mon Sep 17 00:00:00 2001 From: Ricky Date: Sat, 20 Jul 2019 12:42:54 +1000 Subject: [PATCH 07/12] removing flakly reg-ex assertion --- src/test/java/com/github/javafaker/CountryTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/github/javafaker/CountryTest.java b/src/test/java/com/github/javafaker/CountryTest.java index 74e442c3..ab6b3836 100644 --- a/src/test/java/com/github/javafaker/CountryTest.java +++ b/src/test/java/com/github/javafaker/CountryTest.java @@ -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; @@ -43,6 +44,6 @@ public class CountryTest extends AbstractFakerTest { @Test public void testName() { - assertThat(faker.country().name(), matchesRegularExpression("([\\w-]+ ?)+")); + assertThat(faker.country().name(), isStringWithContents()); } } From aa1735a6b5bb33ae52e977b8682ba089ec41d0b2 Mon Sep 17 00:00:00 2001 From: Ricky Date: Sat, 20 Jul 2019 16:02:48 +1000 Subject: [PATCH 08/12] made the countyByZipcode test not random --- src/test/java/com/github/javafaker/AddressTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/github/javafaker/AddressTest.java b/src/test/java/com/github/javafaker/AddressTest.java index 2163b6a1..352589a3 100644 --- a/src/test/java/com/github/javafaker/AddressTest.java +++ b/src/test/java/com/github/javafaker/AddressTest.java @@ -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())); } } From 396ca36a17b8d8b53e1ce90f7c8a0c9f6fa7b1cd Mon Sep 17 00:00:00 2001 From: Ricky Date: Sat, 20 Jul 2019 16:19:54 +1000 Subject: [PATCH 09/12] [maven-release-plugin] prepare release javafaker-1.0.0 --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7a5cbe75..aab6d29b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.javafaker javafaker jar - 0.19-SNAPSHOT + 1.0.0 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. @@ -13,6 +13,7 @@ UTF-8 UTF-8 + -Xdoclint:none From 9c1f1d6668e41f3e181e6cba81bb302f7e8a40c9 Mon Sep 17 00:00:00 2001 From: Ricky Date: Sat, 20 Jul 2019 16:20:04 +1000 Subject: [PATCH 10/12] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aab6d29b..f212886d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.javafaker javafaker jar - 1.0.0 + 1.0.1-SNAPSHOT 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. From df2876d8ddd5e4f32a95190b332599213bc5550d Mon Sep 17 00:00:00 2001 From: Ricky Yim Date: Sat, 20 Jul 2019 21:03:15 +1000 Subject: [PATCH 11/12] Update README.md Added demo web application link --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 01cc4f81..182d6a58 100644 --- a/README.md +++ b/README.md @@ -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 From 309f109707a0662071f5744c6bcc295761e01cdf Mon Sep 17 00:00:00 2001 From: Ricky Yim Date: Sun, 21 Jul 2019 15:23:45 +1000 Subject: [PATCH 12/12] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 182d6a58..148eff89 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ In pom.xml, add the following xml stanza between ` ... com.github.javafaker javafaker - 0.18 + 1.0.0 ``` @@ -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' } ```