Skip to content
Snippets Groups Projects
Commit 59901df0 authored by Erik Moravec's avatar Erik Moravec
Browse files

test: added test case for remove not present home game, little refactoring to...

test: added test case for remove not present home game, little refactoring to use more readable assert methods
parent c7ee3d79
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ package cz.muni.fi.pa165.icehockeymanager.services;
import cz.muni.fi.pa165.icehockeymanager.config.ApplicationConfig;
import cz.muni.fi.pa165.icehockeymanager.dao.TeamDao;
import cz.muni.fi.pa165.icehockeymanager.exceptions.PlayerNotInTeamException;
import cz.muni.fi.pa165.icehockeymanager.exceptions.UnknownGameException;
import cz.muni.fi.pa165.icehockeymanager.model.Game;
import cz.muni.fi.pa165.icehockeymanager.model.Player;
import cz.muni.fi.pa165.icehockeymanager.model.Team;
......@@ -140,7 +141,7 @@ class TeamServiceImplTest {
Team team = buildTeam("Florida Panthers");
Game game = buildGame();
teamService.addHomeGame(team, game);
assertThat(team.getHomeGames()).hasSameElementsAs(List.of(game));
assertThat(team.getHomeGames()).containsOnly(game);
verify(teamDao).update(team);
}
......@@ -166,7 +167,7 @@ class TeamServiceImplTest {
Team team = buildTeam("Florida Panthers");
Game game = buildGame();
teamService.addAwayGame(team, game);
assertThat(team.getAwayGames()).hasSameElementsAs(List.of(game));
assertThat(team.getAwayGames()).containsOnly(game);
verify(teamDao).update(team);
}
......@@ -198,14 +199,14 @@ class TeamServiceImplTest {
}
@Test
public void removeHomeGameOnOfMany() {
public void removeHomeGameOneOfMany() {
Team team = buildTeam("Florida Panthers");
Game game = buildGame();
game.setId(2L);
Game game2 = buildGame();
team.setHomeGames(Set.of(game, game2));
teamService.removeHomeGame(team, game);
assertThat(team.getHomeGames()).hasSameElementsAs(Set.of(game2));
assertThat(team.getHomeGames()).containsOnly(game2);
verify(teamDao).update(team);
}
......@@ -215,7 +216,7 @@ class TeamServiceImplTest {
assertThatExceptionOfType(NullPointerException.class).isThrownBy(
() -> teamService.addHomeGame(team, null)
);
assertThat(team.getHomeGames()).hasSameElementsAs(List.of());
assertThat(team.getHomeGames()).isEmpty();
}
@Test
......@@ -226,6 +227,19 @@ class TeamServiceImplTest {
);
}
@Test
public void removeHomeGameNotPresent() {
Team team = buildTeam("Florida Panthers");
Game game = buildGame();
game.setId(2L);
Game game2 = buildGame();
team.setHomeGames(Set.of(game));
assertThatExceptionOfType(UnknownGameException.class).isThrownBy(
() -> teamService.removeHomeGame(team, game2)
);
assertThat(team.getHomeGames()).containsOnly(game);
}
private Game buildGame() {
var game = new Game();
game.setId(1L);
......
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