Skip to content
Snippets Groups Projects
Commit afb7f23f authored by Tomas Madeja's avatar Tomas Madeja Committed by Ján Dovjak
Browse files

feat: userFacade::getGamesForLeague implemented

parent d0cadfad
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import cz.muni.fi.pa165.icehockeymanager.exceptions.UnknownTeamException;
import cz.muni.fi.pa165.icehockeymanager.model.Game;
import cz.muni.fi.pa165.icehockeymanager.model.Team;
import cz.muni.fi.pa165.icehockeymanager.services.BeanMappingService;
import cz.muni.fi.pa165.icehockeymanager.services.GameService;
import cz.muni.fi.pa165.icehockeymanager.services.PlayerService;
import cz.muni.fi.pa165.icehockeymanager.services.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -24,12 +25,15 @@ public class UserFacadeImpl implements UserFacade {
private final TeamService teamService;
private final GameService gameService;
private final BeanMappingService beanMappingService;
@Autowired
public UserFacadeImpl(PlayerService playerService, TeamService teamService, BeanMappingService beanMappingService) {
public UserFacadeImpl(PlayerService playerService, TeamService teamService, GameService gameService, BeanMappingService beanMappingService) {
this.playerService = playerService;
this.teamService = teamService;
this.gameService = gameService;
this.beanMappingService = beanMappingService;
}
......@@ -45,7 +49,8 @@ public class UserFacadeImpl implements UserFacade {
@Override
public Collection<GameDTO> getGamesForLeague() {
return null;
var games = gameService.getAllGames();
return beanMappingService.mapTo(games, GameDTO.class);
}
@Override
......
......@@ -10,6 +10,7 @@ import cz.muni.fi.pa165.icehockeymanager.model.Player;
import cz.muni.fi.pa165.icehockeymanager.model.Team;
import cz.muni.fi.pa165.icehockeymanager.services.BeanMappingService;
import cz.muni.fi.pa165.icehockeymanager.services.BeanMappingServiceImpl;
import cz.muni.fi.pa165.icehockeymanager.services.GameService;
import cz.muni.fi.pa165.icehockeymanager.services.PlayerService;
import cz.muni.fi.pa165.icehockeymanager.services.TeamService;
import org.junit.jupiter.api.BeforeEach;
......@@ -47,6 +48,8 @@ class UserFacadeImplTest {
private TeamService teamService;
private GameService gameService;
private BeanMappingService beanMappingService;
private UserFacade userFacade;
......@@ -55,8 +58,9 @@ class UserFacadeImplTest {
public void setUp() {
playerService = mock(PlayerService.class);
teamService = mock(TeamService.class);
gameService = mock(GameService.class);
beanMappingService = context.getBean(BeanMappingServiceImpl.class);
userFacade = new UserFacadeImpl(playerService, teamService, beanMappingService);
userFacade = new UserFacadeImpl(playerService, teamService, gameService, beanMappingService);
}
@Test
......@@ -206,9 +210,60 @@ class UserFacadeImplTest {
@Test
public void getAllGamesInLeagueNoGames() {
when(gameService.getAllGames()).thenReturn(new ArrayList<>());
assertThat(userFacade.getGamesForLeague()).isEmpty();
}
@Test
public void getAllGamesInLeagueFoundGames() {
var teamPenguins = buildTeamMock(1L, "Pittsburgh Penguins");
var teamBruins = buildTeamMock(2L, "Boston Bruins");
var gameOne = buildGameMock(1L, null, 1, 2, "2020-01-01 16:00 GMT");
var gameTwo = buildGameMock(2L, null, 0, 0, "2020-02-01 16:00 GMT");
var gameThree = buildGameMock(3L, null, 2, 1, "2020-01-02 16:00 GMT");
var gameFour = buildGameMock(4L, null, 0, 0, "2020-02-02 16:00 GMT");
addHomeGames(teamPenguins, gameOne, gameTwo);
addAwayGames(teamPenguins, gameThree, gameFour);
addAwayGames(teamBruins, gameOne, gameTwo);
addHomeGames(teamBruins, gameThree, gameFour);
var teamPenguinsDTO = buildTeamDTO(1L, "Pittsburgh Penguins");
var teamBruinsDTO = buildTeamDTO(2L, "Boston Bruins");
var expected = asCollection(
buildGameDTO(
1L,
teamPenguinsDTO, teamBruinsDTO,
null,
1, 2,
"2020-01-01 16:00 GMT"),
buildGameDTO(
2L,
teamPenguinsDTO, teamBruinsDTO,
null,
0, 0,
"2020-02-01 16:00 GMT"),
buildGameDTO(
3L,
teamBruinsDTO, teamPenguinsDTO,
null,
2, 1,
"2020-01-02 16:00 GMT"),
buildGameDTO(
4L,
teamBruinsDTO, teamPenguinsDTO,
null,
0, 0,
"2020-02-02 16:00 GMT")
);
when(gameService.getAllGames()).thenReturn(Arrays.asList(gameOne, gameTwo, gameThree, gameFour));
assertThat(userFacade.getGamesForLeague()).containsExactlyElementsOf(expected);
}
public Player buildPlayerMock(Long id, String name) {
var player = mock(Player.class);
when(player.getId()).thenReturn(id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment