From b4cac6242bf7c7abf6af88ff9f1452501bc00ba9 Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Sun, 6 Jun 2021 21:21:21 +0200 Subject: [PATCH] test: added test for broadCastToAllExcept in LobbyConnectionTest --- .../lobbymanager/LobbyConnectionTest.java | 42 ++++++++++++++++++- 1 file changed, 41 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 60b84b1..538fb8f 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 @@ -195,7 +195,6 @@ class LobbyConnectionTest { connection.broadcastEvents(events); - verify(sendMessageCallback).accept(playerOne.getConnection(), message); verify(sendMessageCallback).accept(playerTwo.getConnection(), message); verify(sendMessageCallback).accept(spectatorOne.getConnection(), message); @@ -215,4 +214,45 @@ class LobbyConnectionTest { assertThat(hashSet).containsOnly(connection); } + @Test + void broadcastToAllExceptTest(){ + var player1 = mock(WebSocket.class); + var player2 = mock(WebSocket.class); + var spectator1 = mock(WebSocket.class); + var spectator2 = mock(WebSocket.class); + + Participant playerOne = new Participant(player1, ParticipantType.PlayerOne, "playerOne"); + Participant playerTwo = new Participant(player2, ParticipantType.PlayerTwo, "playerTwo"); + Participant spectatorOne = new Participant(spectator1, ParticipantType.Spectator, "spectatorOne"); + Participant spectatorTwo = new Participant(spectator2, ParticipantType.Spectator, "spectatorTwo"); + + connection.addPlayer(playerOne); + connection.addPlayer(playerTwo); + connection.addSpectator(spectatorOne); + connection.addSpectator(spectatorTwo); + + var events = new Event[]{ + new EventBuilder(EventType.PauseStartEvent).buildGameEvent(), + new EventBuilder(EventType.MoveEvent).buildGameEvent() + }; + + var message = new EventMessage(); + message.messages = events; + + connection.broadcastToAllExcept(playerTwo, events); + + verify(sendMessageCallback).accept(playerOne.getConnection(), message); + //playerTwo is the only one who doesn't receive the message + verify(sendMessageCallback, never()).accept(playerTwo.getConnection(), message); + verify(sendMessageCallback).accept(spectatorOne.getConnection(), message); + verify(sendMessageCallback).accept(spectatorTwo.getConnection(), message); + } + + @Test + void terminateTest(){ + assertThat(connection.isActive()).isFalse(); + connection.terminateConnection(); + assertThat(connection.isActive()).isTrue(); + } + }