From 8dab25ca8d637e658098b2b3c775debe793149e1 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Sun, 6 Jun 2021 18:43:38 +0200 Subject: [PATCH] test: fixed LobbyManagerTest to not run lobbies --- .../server/lobbymanager/LobbyManagerTest.java | 20 +++++++++++++++++++ 1 file changed, 20 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 8bd8046..dce5465 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 @@ -1,9 +1,12 @@ package uulm.teamname.marvelous.server.lobbymanager; import org.java_websocket.WebSocket; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; import uulm.teamname.marvelous.gamelibrary.messages.BasicMessage; import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; import uulm.teamname.marvelous.gamelibrary.messages.RoleEnum; @@ -33,6 +36,9 @@ class LobbyManagerTest { Participant player2Participant; Participant player3Participant; + LobbyRunner lobbyRunner; + MockedStatic lobbyRunnerMockedStatic; + @BeforeEach void beforeEach() { @@ -67,6 +73,17 @@ class LobbyManagerTest { player3, ParticipantType.PlayerOne, "AwesomestAwesomePlayer"); + + lobbyRunner = spy(LobbyRunner.getInstance()); + doNothing().when(lobbyRunner).startLobby(any(LobbyConnection.class)); + + lobbyRunnerMockedStatic = Mockito.mockStatic(LobbyRunner.class); + lobbyRunnerMockedStatic.when(LobbyRunner::getInstance).thenReturn(lobbyRunner); + } + + @AfterEach + void afterEach() { + lobbyRunnerMockedStatic.close(); } @Test @@ -77,6 +94,9 @@ class LobbyManagerTest { @Test @DisplayName("When a participant is added, a new Lobby is created") void lobbyCreationTest() { + + + var message = new PlayerReadyMessage(); message.role = RoleEnum.PLAYER;