From e544c00d2eaebb0c6a7479f6baf7f44bcdc80dff Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Sun, 6 Jun 2021 19:27:40 +0200 Subject: [PATCH] test: created test for LobbyRunner --- .../server/lobbymanager/LobbyRunnerTest.java | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyRunnerTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyRunnerTest.java index af51587..4d66dbe 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyRunnerTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobbymanager/LobbyRunnerTest.java @@ -1,28 +1,67 @@ package uulm.teamname.marvelous.server.lobbymanager; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import uulm.teamname.marvelous.server.Server; +import java.lang.reflect.InvocationTargetException; import java.util.concurrent.*; import static org.mockito.Mockito.*; import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; class LobbyRunnerTest { LobbyConnection connection; + LobbyRunner lobbyRunner; + + MockedStatic serverMockedStatic; @BeforeEach - void setUp() { + void setUp() + throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { connection = mock(LobbyConnection.class); + // when(connection.gameID).thenReturn("/SomeGameID"); + var constructor = LobbyRunner.class.getDeclaredConstructor(); + constructor.setAccessible(true); + + lobbyRunner = constructor.newInstance(); + + serverMockedStatic = mockStatic(Server.class); + serverMockedStatic.when(Server::getMaxLobbies).thenReturn(1); + } + + @AfterEach + void tearDown() { + serverMockedStatic.close(); + } + + + // It seems very impractical indeed to properly to check if another thread executed this, so I won't + @Test + void lobbyGetsStartedTest() { + lobbyRunner.startLobby(connection); + verify(connection).run(); } @Test - void lobbyGetsStartedTest() { - + void canAddLobbyTest() { + assertThat(lobbyRunner.canAddLobby()).isTrue(); + lobbyRunner.startLobby(connection); + assertThat(lobbyRunner.canAddLobby()).isFalse(); + } + @Test + void removeLobbyRemovesLobbyAndSetsTerminationFlag() { + lobbyRunner.startLobby(connection); } }