From 4dec57d483767bef75676cee6c7da99c4e7ec290 Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Sat, 5 Jun 2021 23:28:17 +0200 Subject: [PATCH] test: created test for TurnTimer --- .../marvelous/server/lobby/Lobby.java | 1 + .../marvelous/server/lobby/TurnTimerTest.java | 32 +++++++++++++++++++ .../server/lobby/pipelining/PacketTest.java | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 Server/src/test/java/uulm/teamname/marvelous/server/lobby/TurnTimerTest.java diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java index 6eaac8e..70269f7 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java @@ -33,6 +33,7 @@ public class Lobby { PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) { + this.gameID = gameID; this.connection = connection; diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/TurnTimerTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/TurnTimerTest.java new file mode 100644 index 0000000..2fa5755 --- /dev/null +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/TurnTimerTest.java @@ -0,0 +1,32 @@ +package uulm.teamname.marvelous.server.lobby; + +import org.java_websocket.WebSocket; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; +import uulm.teamname.marvelous.server.lobbymanager.LobbyConnection; +import uulm.teamname.marvelous.server.lobbymanager.Participant; + +import java.util.function.Consumer; + +import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +class TurnTimerTest { + TurnTimer turnTimer; + + @BeforeEach + void beforeEach(){ + var callback = mock(Consumer.class); + turnTimer = new TurnTimer(20, callback); + } + + @Test + void startTurnTimerTest(){ + var connection = mock(WebSocket.class); + var participant = new Participant(connection, ParticipantType.Spectator, "spectator"); + assertThatIllegalStateException().describedAs("Spectators don't have TurnTime").isThrownBy(() -> turnTimer.startTurnTimer(participant)); + } + +} \ No newline at end of file diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PacketTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PacketTest.java index 5923971..a91e853 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PacketTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PacketTest.java @@ -47,7 +47,7 @@ class PacketTest { new RequestBuilder(RequestType.Req).buildGameRequest(), new RequestBuilder(RequestType.MoveRequest).buildGameRequest() }; - var participant = new Participant(null, ParticipantType.PlayerOne, "PlaerOne"); + var participant = new Participant(null, ParticipantType.PlayerOne, "PlayerOne"); packet = new Packet(requests, participant); assertThat(packet.getOrigin()).isEqualTo(participant);