Skip to content

Commit

Permalink
Add Baseball provider (#548)
Browse files Browse the repository at this point in the history
* Add Baseball provider

* Change order of SportProviders method in alphabetical ascending order

* Change Version number to 1.7.0

Co-authored-by: Ji Myoung Ha <NoPlayer40600@gmail.com>
  • Loading branch information
Blackcows and NULL0xFF committed Nov 11, 2022
1 parent d1e75c5 commit 2015bcb
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ Providers
* Babylon 5
* Back To The Future
* Barcode
* Baseball
* Basketball
* Battlefield 1
* Beer
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/net/datafaker/providers/sport/Baseball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.datafaker.providers.sport;

import net.datafaker.providers.base.AbstractProvider;

/**
* Generate random components of baseball game, e.g. teams, coaches, positions and players.
*
* @since 1.7.0
*/
public class Baseball extends AbstractProvider<SportProviders> {

/**
Baseball
* Create a constructor for Baseball.
*
* @param faker The Faker instance for generating random, different kinds of disease, e.g. the internal disease.
*/
protected Baseball(SportProviders faker) {
super(faker);
}

/**
* Generate random Baseball teams
*
* @return Baseball teams
*/
public String teams() {
return resolve("baseball.teams");
}

/**
* Generate random coaches in baseball game
*
* @return Baseball coaches
*/
public String coaches() {
return resolve("baseball.coaches");
}

/**
* Generate random positions in baseball game
*
* @return Baseball positions
*/
public String positions() {
return resolve("baseball.positions");
}

/**
* Generate random baseball players
*
* @return Baseball players
*/
public String players() {
return resolve("baseball.players");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import net.datafaker.providers.base.ProviderRegistration;

public interface SportProviders extends ProviderRegistration {
default Baseball baseball() {
return getProvider(Baseball.class, Baseball::new);
}

default Basketball basketball() {
return getProvider(Basketball.class, Basketball::new);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/datafaker/service/files/EnFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public String getPath() {
"babylon5.yml",
"back_to_the_future.yml",
"barcode.yml",
"baseball.yml",
"basketball.yml",
"battlefield1.yml",
"beer.yml",
Expand Down
50 changes: 50 additions & 0 deletions src/main/resources/en/baseball.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
en:
faker:
baseball:
teams:
- Boston Red Sox
- Los Angeles Angels
- Los Angeles Dodgers
- New York Yankees
- Detroit Tigers
- New York Mets

players:
- Bobby Doerr
- Joe Cronin
- Pesky Paveskovich
- Carl Yastrzemski
- Carlton Fisk
- Billy Martin
- Derek Jeter
- Babe Ruth
- Lou Gehrig
- Joe DiMaggio
- Joe Torre
- Mickey Mantle
- Bill Dickey
- Yogi Berra
- Roger Maris

coaches:
- Aaron Boone
- Brian Snitker
- Dave Roberts
- Alex Cora
- A.J. Hinch
- Brandon Hyde
- Torey Lovullo

positions:
- Pitcher
- Catcher
- First Baseman
- Second Baseman
- Third Baseman
- Short Stop
- Left Fielder
- Center Fielder
- Right Fielder
- Designated Hitter
- Pinch Hitter
- Pinch Runner
28 changes: 28 additions & 0 deletions src/test/java/net/datafaker/providers/sport/BaseballTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.datafaker.providers.sport;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class BaseballTest extends SportFakerTest {

@Test
void testTeams() {
assertThat(faker.baseball().teams()).matches("[\\p{L}'()., 0-9-’]+");
}

@Test
void testCoaches() {
assertThat(faker.baseball().coaches()).matches("[\\p{L}'()., 0-9-’]+");
}

@Test
void testPositions() {
assertThat(faker.baseball().positions()).matches("[\\p{L}'()., 0-9-’]+");
}

@Test
void testPlayers() {
assertThat(faker.baseball().players()).matches("[\\p{L}'()., 0-9-’]+");
}
}

0 comments on commit 2015bcb

Please sign in to comment.