test: added test for broadcastEvents with a list of Events
This commit is contained in:
parent
e7f22099b1
commit
355698db1b
@ -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<Event>();
|
||||
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<LobbyConnection>();
|
||||
@ -254,5 +284,4 @@ class LobbyConnectionTest {
|
||||
connection.terminateConnection();
|
||||
assertThat(connection.isActive()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user