From 355698db1b8e6b869fb8f9edc182b8d32c02cfce Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Sun, 6 Jun 2021 21:40:53 +0200 Subject: [PATCH] test: added test for broadcastEvents with a list of Events --- .../lobbymanager/LobbyConnectionTest.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnectionTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnectionTest.java index 538fb8f..be96014 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnectionTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyConnectionTest.java @@ -13,7 +13,9 @@ import org.java_websocket.WebSocket; import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; import uulm.teamname.marvelous.gamelibrary.messages.server.EventMessage; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.function.BiConsumer; import static org.mockito.Mockito.*; @@ -201,6 +203,34 @@ class LobbyConnectionTest { verify(sendMessageCallback).accept(spectatorTwo.getConnection(), message); } + @Test + void broadcastEventsListToArrayTest(){ + var player1 = mock(WebSocket.class); + var player2 = mock(WebSocket.class); + var spectatorSocket = mock(WebSocket.class); + + Participant playerOne = new Participant(player1, ParticipantType.PlayerOne, "playerOne"); + Participant playerTwo = new Participant(player2, ParticipantType.PlayerTwo, "playerTwo"); + Participant spectator = new Participant(spectatorSocket, ParticipantType.Spectator, "spectator"); + + connection.addPlayer(playerOne); + connection.addPlayer(playerTwo); + connection.addSpectator(spectator); + + var events = new ArrayList(); + events.add(new EventBuilder(EventType.PauseStartEvent).buildGameEvent()); + events.add(new EventBuilder(EventType.MoveEvent).buildGameEvent()); + + connection.broadcastEvents(events); + + var message = new EventMessage(); + message.messages = events.toArray(new Event[0]); + + verify(sendMessageCallback).accept(playerOne.getConnection(), message); + verify(sendMessageCallback).accept(playerTwo.getConnection(), message); + verify(sendMessageCallback).accept(spectator.getConnection(), message); + } + @Test void hashCodeTest() { var hashSet = new HashSet(); @@ -254,5 +284,4 @@ class LobbyConnectionTest { connection.terminateConnection(); assertThat(connection.isActive()).isTrue(); } - }