From 4ed6d23be6b1ebd944ad82c14e263ff23f7fe694 Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Sun, 6 Jun 2021 20:00:39 +0200 Subject: [PATCH] test: added test for spectator joins full lobby (need fix) --- .../server/lobbymanager/LobbyManagerTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManagerTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManagerTest.java index dce5465..c57b50c 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManagerTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyManagerTest.java @@ -260,4 +260,47 @@ class LobbyManagerTest { .isEqualTo(manager.getLobbies().get(player3Participant)); } + @Test + @DisplayName("Spectator joins full lobby") + void spactatorsJoinLobby(){ + when(player1.getResourceDescriptor()).thenReturn(null); + when(player2.getResourceDescriptor()).thenReturn(null); + + Participant player1Participant = new Participant(player1, ParticipantType.PlayerOne, "playerOne"); + Participant player2Participant = new Participant(player2, ParticipantType.PlayerTwo, "playerTwo"); + Participant spectator1 = new Participant(spectator, ParticipantType.Spectator, "spectator1"); + Participant spectator2 = new Participant(spectator, ParticipantType.Spectator, "spectator2"); + + manager.assignLobbyToConnection(player1, "playerOne", playerReady); + manager.assignLobbyToConnection(player2, "playerTwo", playerReady); + manager.assignLobbyToConnection(spectator, "spectator1", spectatorReady); + manager.assignLobbyToConnection(spectator, "spectator2", spectatorReady); + + assertThat(manager.getResourceDescriptorToLobby()).hasSize(2); + assertThat(manager.getLobbies()).containsOnlyKeys( + player1Participant, + player2Participant, + spectator1, + spectator2 + ); + assertThat(manager.getLobbies().get(player1Participant)) + .isNotNull() + .isEqualTo(manager.getLobbies().get(player2Participant)); + assertThat(manager.getLobbies().get(spectator1)) + .isNotNull() + .isEqualTo(manager.getLobbies().get(spectator2)); + +// TODO: Why are the following tests wrong? + +// assertThat(manager.getResourceDescriptorToLobby().get(manager.getLobbies().get(player1Participant).gameID)) +// .isNotNull() +// .isEqualTo(manager.getLobbies().get(player1Participant)) +// .isEqualTo(manager.getLobbies().get(player2Participant)) +// .isEqualTo(manager.getLobbies().get(spectator1)) +// .isEqualTo(manager.getLobbies().get(spectator2)); +// assertThat(manager.getResourceDescriptorToLobby().get(manager.getLobbies().get(player1Participant).gameID)) +// .isEqualTo(manager.getResourceDescriptorToLobby().get(manager.getLobbies().get(player2Participant).gameID)) +// .isEqualTo(manager.getResourceDescriptorToLobby().get(manager.getLobbies().get(spectator1).gameID)) +// .isEqualTo(manager.getResourceDescriptorToLobby().get(manager.getLobbies().get(spectator2).gameID)); + } }