From 7f512400dfa109068b82493f635f0780e4f3770f Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Sun, 6 Jun 2021 00:49:53 +0200 Subject: [PATCH] test: added TimeoutWarning and generateWin tests --- .../marvelous/server/lobby/LobbyTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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 73eb330..b10ea1f 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 @@ -8,6 +8,8 @@ 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; import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder; @@ -57,4 +59,40 @@ class LobbyTest { lobby.receiveRequests(requests, playerOne); } + @Test + void soonTimeoutTest(){ + var participant = mock(Participant.class); + lobby.soonTimeout(participant); + verify(connection).sendEvents(participant, new EventBuilder(EventType.TimeoutWarningEvent).buildGameStateEvent()); + } + + @Test + void generateWinPlayer1Test(){ + var webSoc = mock(WebSocket.class); + Participant winner = new Participant(webSoc, ParticipantType.PlayerOne, "playerOne"); + lobby.generateWin(winner); + verify(connection).broadcastEvents( + new EventBuilder(EventType.WinEvent) + .withPlayerWon(1) + .buildGameStateEvent(), + new EventBuilder(EventType.DisconnectEvent) + .buildGameStateEvent()); + verify(connection).terminateConnection(); + } + + @Test + void generateWinPlayer2Test(){ + var webSoc = mock(WebSocket.class); + Participant winner = new Participant(webSoc, ParticipantType.PlayerOne, "playerOne"); + lobby.generateWin(winner); + verify(connection).broadcastEvents( + new EventBuilder(EventType.WinEvent) + .withPlayerWon(2) + .buildGameStateEvent(), + new EventBuilder(EventType.DisconnectEvent) + .buildGameStateEvent()); + verify(connection).terminateConnection(); + } + + }