From 59901df09b537cc116890ebcecbdcbad6b8c6175 Mon Sep 17 00:00:00 2001 From: Erik Moravec <xmoravec@fi.muni.cz> Date: Wed, 28 Apr 2021 17:51:38 +0200 Subject: [PATCH] test: added test case for remove not present home game, little refactoring to use more readable assert methods --- .../services/TeamServiceImplTest.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/test/java/cz/muni/fi/pa165/icehockeymanager/services/TeamServiceImplTest.java b/src/test/java/cz/muni/fi/pa165/icehockeymanager/services/TeamServiceImplTest.java index e4d565d..89cb5ac 100644 --- a/src/test/java/cz/muni/fi/pa165/icehockeymanager/services/TeamServiceImplTest.java +++ b/src/test/java/cz/muni/fi/pa165/icehockeymanager/services/TeamServiceImplTest.java @@ -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); -- GitLab