From c4badaf4efd95f48207c9cfd4bd45d5ba441e4ce Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Mon, 7 Jun 2021 16:44:04 +0200 Subject: [PATCH] test: refactored tests --- .../teamname/marvelous/server/lobby/LobbyTest.java | 11 ++++------- .../marvelous/server/lobby/TurnTimeoutTimerTest.java | 8 ++++---- .../lobby/pipelining/RequestGameLogicSegmentTest.java | 4 ++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/LobbyTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/LobbyTest.java index cd782f8..7d37aec 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/LobbyTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/LobbyTest.java @@ -9,7 +9,6 @@ import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.config.FieldType; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig; -import uulm.teamname.marvelous.gamelibrary.entities.EntityType; import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; import uulm.teamname.marvelous.gamelibrary.events.EventType; import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; @@ -22,9 +21,7 @@ import uulm.teamname.marvelous.server.netconnector.Client; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -import static org.assertj.core.api.Assertions.*; class LobbyTest { @@ -64,7 +61,7 @@ class LobbyTest { new RequestBuilder(RequestType.MoveRequest).buildGameRequest() }; var playerConnection = mock(WebSocket.class); - doNothing().when(lobby).updateTimer(); + doNothing().when(lobby).updateTurnTimer(); Participant playerOne = new Participant( new Client(playerConnection), "LobbyOne", ParticipantType.PlayerOne); @@ -75,7 +72,7 @@ class LobbyTest { @Disabled void soonTimeoutTest(){ var participant = mock(Participant.class); - lobby.soonTimeout(participant); + lobby.soonTimeout(participant, 15); verify(connection).sendEvents(participant, new EventBuilder(EventType.TimeoutWarningEvent).buildGameStateEvent()); } @@ -84,7 +81,7 @@ class LobbyTest { void generateWinPlayer1Test(){ var webSoc = mock(WebSocket.class); Participant winner = new Participant(new Client(webSoc), "someLobby", ParticipantType.PlayerOne); - lobby.generateWin(winner); + lobby.triggerWin(winner); verify(connection).broadcastEvents( new EventBuilder(EventType.WinEvent) .withPlayerWon(1) @@ -99,7 +96,7 @@ class LobbyTest { void generateWinPlayer2Test(){ var webSoc = mock(WebSocket.class); Participant winner = new Participant(new Client(webSoc), "someLobby", ParticipantType.PlayerOne); - lobby.generateWin(winner); + lobby.triggerWin(winner); verify(connection).broadcastEvents( new EventBuilder(EventType.WinEvent) .withPlayerWon(2) diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/TurnTimeoutTimerTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/TurnTimeoutTimerTest.java index 97dfb5c..9343c54 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/TurnTimeoutTimerTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/TurnTimeoutTimerTest.java @@ -12,20 +12,20 @@ import java.util.function.Consumer; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -class TimeoutTimerTest { - TimeoutTimer timeoutTimer; +class TurnTimeoutTimerTest { + TurnTimeoutTimer turnTimeoutTimer; @BeforeEach void beforeEach(){ var callback = mock(Consumer.class); - timeoutTimer = new TimeoutTimer(20, callback); + turnTimeoutTimer = new TurnTimeoutTimer(20, callback); } @Test void startTurnTimerTest(){ var connection = mock(WebSocket.class); var participant = new Participant(new Client(connection), "lobby", ParticipantType.Spectator); - assertThatIllegalStateException().describedAs("Spectators don't have TurnTime").isThrownBy(() -> timeoutTimer.startTurnTimer(participant)); + assertThatIllegalStateException().describedAs("Spectators don't have TurnTime").isThrownBy(() -> turnTimeoutTimer.startTurnTimer(participant)); } } diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameLogicSegmentTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameLogicSegmentTest.java index 55a9076..3f26213 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameLogicSegmentTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameLogicSegmentTest.java @@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; -class RequestGameStateSegmentTest { +class RequestGameLogicSegmentTest { @Test void requestGamestateTest(){ @@ -42,4 +42,4 @@ class RequestGameStateSegmentTest { verify(game).getGameStateEvent(); } -} \ No newline at end of file +}