Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swift code feature #725

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Fakers
* Back To The Future
* Aviation
* Basketball
* Battlefield1
* Beer
* Bojack Horseman
* Book
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/github/javafaker/Battlefield1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.github.javafaker;

/**
* CS304 Issue link: https://github.com/DiUS/java-faker/issues/711
* A class for generating random value of Battlefield1 contents
* @author coolestjj
*/

public class Battlefield1 {

private final Faker faker;

protected Battlefield1(final Faker faker) {
this.faker = faker;
}

/**
*
* @return a random unit class name as a string value
*/
public String classes() {
return faker.resolve("battlefield1.classes");
}

/**
*
* @return a random weapon name as a string value
*/
public String weapon() {
return faker.resolve("battlefield1.weapon");
}

/**
*
* @return a random vehicle name as a string value
*/
public String vehicle() {
return faker.resolve("battlefield1.vehicle");
}

/**
*
* @return a random map title as a string value
*/
public String map() {
return faker.resolve("battlefield1.map");
}

/**
*
* @return a random faction name as a string value
*/
public String faction() {
return faker.resolve("battlefield1.faction");
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/github/javafaker/Faker.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public class Faker {
private final Sip sip;
private final EnglandFootBall englandfootball;
private final Mountain mountain;
private final Battlefield1 battlefield1;
private final SwiftCode swiftCode;

public Faker() {
this(Locale.ENGLISH);
Expand Down Expand Up @@ -223,6 +225,8 @@ public Faker(FakeValuesService fakeValuesService, RandomService random) {
this.sip = new Sip(this);
this.englandfootball = new EnglandFootBall(this);
this.mountain = new Mountain(this);
this.battlefield1 = new Battlefield1(this);
this.swiftCode = new SwiftCode(this);
}

/**
Expand Down Expand Up @@ -691,6 +695,14 @@ public StarCraft starCraft() {

public Mountain mountain() { return mountain; }

public Battlefield1 battlefield1() {
return battlefield1;
}

public SwiftCode swiftCode() {
return swiftCode;
}

public String resolve(String key) {
return this.fakeValuesService.resolve(key, this, this);
}
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/github/javafaker/SwiftCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.github.javafaker;

/**
* CS304 Issue link: https://github.com/DiUS/java-faker/issues/721
* A class for generating random swift code
*/

public class SwiftCode {

private final Faker faker;

protected SwiftCode(final Faker faker) {
this.faker = faker;
}

/**
* This function generates a random swift code of a bank's headquarter.

* @return a random swift code of a bank's headquarter as a string value
*/
public String headquarterSwiftcode() {
String chars1 = "ABCDEFGHIZKLMNOPQRSTUVWXYZ";
String chars2 = "0123456789ABCDEFGHIZKLMNOPQRSTUVWXYZ";
StringBuffer swiftcode = new StringBuffer();
for (int i = 0; i < 4; i++) {
String bank = String.valueOf(chars1.charAt((int) (Math.random() * 26)));
swiftcode.append(bank);
}
String country = faker.address().countryCode();
swiftcode.append(country);
for (int i = 0; i < 2; i++) {
String region = String.valueOf(chars2.charAt((int) (Math.random() * 36)));
swiftcode.append(region);
}
swiftcode.append("XXX");
return swiftcode.toString();
}

/**
* This function generates a random swift code of a bank's branch.

* @return a random swift code of a bank's branch as a string value
*/
public String branchSwiftcode() {
String chars1 = "ABCDEFGHIZKLMNOPQRSTUVWXYZ";
String chars2 = "0123456789ABCDEFGHIZKLMNOPQRSTUVWXYZ";
StringBuffer swiftcode = new StringBuffer();
for (int i = 0; i < 4; i++) {
String bank = String.valueOf(chars1.charAt((int) (Math.random() * 26)));
swiftcode.append(bank);
}
String country = faker.address().countryCode();
swiftcode.append(country);
for (int i = 0; i < 2; i++) {
String region = String.valueOf(chars2.charAt((int) (Math.random() * 36)));
swiftcode.append(region);
}
for (int i = 0; i < 3; i++) {
String branch = String.valueOf(chars2.charAt((int) (Math.random() * 36)));
swiftcode.append(branch);
}
return swiftcode.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public String getPath() {
"barcode.yml",
"bank.yml",
"basketball.yml",
"battlefield1.yml",
"beer.yml",
"bojack_horseman.yml",
"book.yml",
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/en/battlefield1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
en:
faker:
battlefield1:
classes: ["Assault", "Medic", "Support", "Scout", "Tanker", "Pilot", "Cavalry", "FlamTrooper", "Sentry", "Tank Hunter", "Trench Raider", "Infiltrator"]
weapon: ["MP 18","Automatico M1918","Hellriegel 1915","Annihilator","M1919 SMG","Ribeyrolles 1918 (TSNP)","SMG 08/18 (TSAR)","M1917 Trench Carbine (TIDE)","Maschinenpistole M1912/P.16 (TIDE)","RSC SMG (APOC)","M97 Trench Gun","Model 10-A","12g Automatic","Sawed Off Shotgun","Sjögren Inertial (TSNP)","Model 1900 (TSAR)","Cei-Rigotti","Selbstlader M1916","M1907 SL","Mondragón","Autoloading 8","Selbstlader 1906","Fedorov-Degtyarev","RSC 1917 (TSNP)","Fedorov Avtomat (TSAR)","General Liu Rifle (TSAR)","Farquhar-Hill (TIDE)","Howell Automatic (APOC)","Lewis Gun","M1909 Benét-Mercié","Madsen MG","MG15 n.A.","BAR M1918","Huot Automatic","BAR M1918A2","Burton LMR","Chauchat (TSNP)","Parabellum MG14/17 (TSAR)","Perino Model 1908 (TSAR)","M1917 MG (TIDE)","lMG 08/18 (APOC)","C96 Carbine","M1911 Extended","P08 Artillerie","Pieper M1893","Mle 1903 Extended (TSNP)","C93 Carbine (TSAR)","SMLE MKIII","Gewehr 98","Russian 1895","Gewehr M.95","M1903","Martini-Henry","Mosin-Nagant M38 Carbine","Lebel Model 1886 (TSNP)","Mosin-Nagant M91 (TSAR)","Vetterli-Vitali M1870/87 (TSAR)","Carcano M91 Carbine (TIDE)","Type 38 Arisaka (TIDE)","Ross MkIII (APOC)","M1917 Enfield (APOC)","C96 Carbine","Frommer Stop Auto","M1911 Extended","Pieper M1893","P08 Artillerie","Mle 1903 Extended (TSNP)","C93 Carbine (TSAR)","Bodeo 1889","Frommer Stop","Mars Automatic","Sawed Off Shotgun","M1911","P08 Pistol","Mle 1903","No. 3 Revolver","C93","Kolibri","M1911A1","Peacekeeper","Nagant Revolver (TSAR)","Obrez Pistol (TSAR)","Revolver Mk VI (APOC)","Wex","MG 08/15","Villar Perosa","Tankgewehr M1918","Martini-Henry Grenade Launcher (TIDE)","Sawed Off Shotgun","No. 3 Revolver"]
vehicle: ["M.A.S. Torpedo Boat","Y-Lighter (TSAR)","Barrage Balloon","Type UE II Submarine","Horse","Carrier Pigeon","Illumination flares (TSNP)","Livens Projector (APOC)","FK 96 n.A.","Heavy Machine Gun","QF 1 AA","Fortress Gun","HE Auto-Cannon","Vickers","Hotchkiss M1914 (TSNP)","BL 9.2 Siege Gun (TSNP)","305/52 O Coastal Gun (TSAR)","SK45 Coastal Cannon (TIDE)","Caproni Ca.5","Gotha G.IV","Ilya-Muromets (TSAR)","Hansa-Brandenburg G.I (APOC)","Airco DH.10","Bristol F2.B","Halberstadt CL.II","Rumpler C.I","A.E.F 2-A2","FT-17 Light Tank"," A7V ","Mark V Landship","Artillery Truck","St Chamond","Putilov-Garford","RNAS Armored Car","EV4 Armored Car","F.T Armored Car","Romfell Armored Car","KFT Scout","M30 Scout","37/95 Scout","MC 3.5HP Sidecar","MC 18J Sidecar"]
map: ["Amiens" , "Argonne Forest" , "Ballroom Blitz" , "Empire's Edge" , "Fao Fortress" , "Monte Grappa", "St. Quentin Scar", "Sinai Desert", "Suez", "Giant's Shadow","Verdun Heights", "Fort De Vaux", "Soissons" , "Rupture","Nivelle Nights", "Prise de Tahure","Łupków Pass","Albion" , "Galicia", "Brusilov Keep", "Tsaritsyn", "Volga River","Achi Baba","Cape Helles" , "Heligoland Bight" , "Zeebrugge", "Caporetto", "Passchendaele" ,"River Somme" , "London Calling", "Razor's Edge"]
faction: ["British Empire", "Kingdom of Italy", "United States", "German Empire", "Austro-Hungarian Empire", "Ottoman Empire", "French Republic", "Russian Empire", "Soviet Union"]
101 changes: 101 additions & 0 deletions src/test/java/com/github/javafaker/Battlefield1Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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.Matchers.not;
import static org.junit.Assert.assertThat;

public class Battlefield1Test extends AbstractFakerTest {

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void classes() {
assertThat(faker.battlefield1().classes(), matchesRegularExpression("[A-Za-z ]+"));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void classesNotNull() {
assertThat(faker.battlefield1().classes(), not(isEmptyOrNullString()));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void weapon() {
assertThat(faker.battlefield1().weapon(), matchesRegularExpression("[A-Za-z0-9, \\-\\.\\(\\)\\/ ]+"));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void weaponNotNull() {
assertThat(faker.battlefield1().weapon(), not(isEmptyOrNullString()));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void vehicle() {
assertThat(faker.battlefield1().vehicle(), matchesRegularExpression("[A-Za-z0-9,\\-\\.\\(\\)\\/ ]+"));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void vehicleNotNull() {
assertThat(faker.battlefield1().vehicle(), not(isEmptyOrNullString()));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void map() {
assertThat(faker.battlefield1().map(), matchesRegularExpression("[A-Za-z0-9,\\-\\.\\(\\)\\' ]+"));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void mapNotNull() {
assertThat(faker.battlefield1().map(), not(isEmptyOrNullString()));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void faction() {
assertThat(faker.battlefield1().faction(), matchesRegularExpression("[A-Za-z,\\- ]+"));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/711
*/
@Test
public void factionNotNull() {
assertThat(faker.battlefield1().faction(), not(isEmptyOrNullString()));
}
}
54 changes: 54 additions & 0 deletions src/test/java/com/github/javafaker/SwiftCodeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;

public class SwiftCodeTest extends AbstractFakerTest {

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/721
*/
@Test
@Repeat(times = 100)
public void headquarterSwiftCodeTest() {
String swiftcode = faker.swiftCode().headquarterSwiftcode();
assertThat(swiftcode, matchesRegularExpression("[0-9A-Z ]+"));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/721
*/
@Test
@Repeat(times = 100)
public void headquarterSwiftCodeNotNull() {
assertThat(faker.swiftCode().headquarterSwiftcode(), not(isEmptyOrNullString()));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/721
*/
@Test
@Repeat(times = 100)
public void branchSwiftCodeTest() {
String swiftcode = faker.swiftCode().branchSwiftcode();
assertThat(swiftcode, matchesRegularExpression("[0-9A-Z ]+"));
}

/**
*
* CS304 (manually written) Issue link: https://github.com/DiUS/java-faker/issues/721
*/
@Test
@Repeat(times = 100)
public void branchSwiftCodeNotNull() {
assertThat(faker.swiftCode().branchSwiftcode(), not(isEmptyOrNullString()));
}
}