@@ -65,6 +65,7 @@ Fakers
|
||||
* Avatar
|
||||
* Back To The Future
|
||||
* Aviation
|
||||
* Basketball
|
||||
* Beer
|
||||
* Book
|
||||
* Bool
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
/**
|
||||
* Generate random components of basketall game, e.g. teams, coaches, positions and players.
|
||||
* @author unknown and irakatz
|
||||
*/
|
||||
public class Basketball {
|
||||
private final Faker faker;
|
||||
|
||||
/**
|
||||
* Create a constructor for Basketball.
|
||||
* @param faker The Faker instance for generating random, different kinds of disease, e.g. the internal disease.
|
||||
*/
|
||||
protected Basketball(Faker faker) {
|
||||
this.faker = faker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random basketball teams
|
||||
* @return Basketball teams
|
||||
*/
|
||||
public String teams() {
|
||||
return faker.fakeValuesService().resolve("basketball.teams", this, faker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random coaches in basketball game
|
||||
* @return Basketball coaches
|
||||
*/
|
||||
public String coaches() {
|
||||
return faker.fakeValuesService().resolve("basketball.coaches", this, faker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random positions in basketball game
|
||||
* @return Basketball positions
|
||||
*/
|
||||
public String positions() {
|
||||
return faker.fakeValuesService().resolve("basketball.positions", this, faker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random basketball players
|
||||
* @return Basketball players
|
||||
*/
|
||||
public String players() {
|
||||
return faker.fakeValuesService().resolve("basketball.players", this, faker);
|
||||
}
|
||||
}
|
||||
@@ -97,6 +97,7 @@ public class Faker {
|
||||
private final AquaTeenHungerForce aquaTeenHungerForce;
|
||||
private final ProgrammingLanguage programmingLanguage;
|
||||
private final Kaamelott kaamelott;
|
||||
private final Basketball basketball;
|
||||
|
||||
public Faker() {
|
||||
this(Locale.ENGLISH);
|
||||
@@ -203,6 +204,7 @@ public class Faker {
|
||||
this.aquaTeenHungerForce = new AquaTeenHungerForce(this);
|
||||
this.programmingLanguage = new ProgrammingLanguage(this);
|
||||
this.kaamelott = new Kaamelott(this);
|
||||
this.basketball = new Basketball(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -491,9 +493,7 @@ public class Faker {
|
||||
return team;
|
||||
}
|
||||
|
||||
public Beer beer() {
|
||||
return beer;
|
||||
}
|
||||
public Beer beer() { return beer; }
|
||||
|
||||
public University university() {
|
||||
return university;
|
||||
@@ -641,6 +641,7 @@ public class Faker {
|
||||
return kaamelott;
|
||||
}
|
||||
|
||||
public Basketball basketball() { return basketball; }
|
||||
public String resolve(String key) {
|
||||
return this.fakeValuesService.resolve(key, this, this);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public class EnFile {
|
||||
"aviation.yml",
|
||||
"back_to_the_future.yml",
|
||||
"bank.yml",
|
||||
"basketball.yml",
|
||||
"beer.yml",
|
||||
"bojack_horseman.yml",
|
||||
"book.yml",
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import com.github.javafaker.AbstractFakerTest;
|
||||
import com.github.javafaker.Faker;
|
||||
import org.junit.Test;
|
||||
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BasketballTest extends AbstractFakerTest {
|
||||
|
||||
@Test
|
||||
public void testPositions(){
|
||||
Faker faker=new Faker();
|
||||
assertThat(faker.basketball().positions(),matchesRegularExpression("[\\p{L}'()\\., 0-9-’’]+")); }
|
||||
|
||||
@Test
|
||||
public void testTeams(){
|
||||
Faker faker=new Faker();
|
||||
assertThat(faker.basketball().teams(),matchesRegularExpression("[\\p{L}'()\\., 0-9-’’]+")); }
|
||||
|
||||
@Test
|
||||
public void testCoaches(){
|
||||
Faker faker=new Faker();
|
||||
assertThat(faker.basketball().coaches(),matchesRegularExpression("[\\p{L}'()\\., 0-9-’’]+")); }
|
||||
|
||||
@Test
|
||||
public void testPlayers(){
|
||||
Faker faker=new Faker();
|
||||
assertThat(faker.basketball().players(),matchesRegularExpression("[\\p{L}'()\\., 0-9-’’]+")); }
|
||||
|
||||
@Test
|
||||
public void testPositionsWith10000Times(){
|
||||
Faker faker=new Faker();
|
||||
boolean isExist=false;
|
||||
for(int i=0;i<10000;i++){
|
||||
String generateString=faker.basketball().positions();
|
||||
if(generateString.equals("Point Guard")){isExist=true;}
|
||||
}
|
||||
assertTrue(isExist);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTeamsWith10000Times(){
|
||||
Faker faker=new Faker();
|
||||
boolean isExist=false;
|
||||
for(int i=0;i<10000;i++){
|
||||
String generateString=faker.basketball().teams();
|
||||
if(generateString.equals("Atlanta Hawks")){isExist=true;}
|
||||
}
|
||||
assertTrue(isExist);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoachesWith10000Times(){
|
||||
Faker faker=new Faker();
|
||||
boolean isExist=false;
|
||||
for(int i=0;i<10000;i++){
|
||||
String generateString=faker.basketball().coaches();
|
||||
if(generateString.equals("Kenny Atkinson")){isExist=true;}
|
||||
}
|
||||
assertTrue(isExist);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayersWith10000Times(){
|
||||
Faker faker=new Faker();
|
||||
boolean isExist=false;
|
||||
for(int i=0;i<10000;i++){
|
||||
String generateString=faker.basketball().players();
|
||||
if(generateString.equals("Joel Embiid")){isExist=true;}
|
||||
}
|
||||
assertTrue(isExist); }
|
||||
}
|
||||
@@ -163,6 +163,7 @@ public class FakerIT {
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.aquaTeenHungerForce());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.programmingLanguage());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.kaamelott());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.basketball());
|
||||
}
|
||||
|
||||
private void testAllMethodsThatReturnStringsActuallyReturnStrings(Object object) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user