test: added test for broadCastToAllExcept in LobbyConnectionTest

This commit is contained in:
Richard Reiber 2021-06-06 21:21:21 +02:00
parent 6470bc09b1
commit b4cac6242b

View File

@ -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();
}
}