test: created test for LobbyRunner
This commit is contained in:
parent
cb2b760866
commit
e544c00d2e
@ -1,28 +1,67 @@
|
|||||||
package uulm.teamname.marvelous.server.lobbymanager;
|
package uulm.teamname.marvelous.server.lobbymanager;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
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 java.util.concurrent.*;
|
||||||
|
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
class LobbyRunnerTest {
|
class LobbyRunnerTest {
|
||||||
|
|
||||||
LobbyConnection connection;
|
LobbyConnection connection;
|
||||||
|
LobbyRunner lobbyRunner;
|
||||||
|
|
||||||
|
MockedStatic<Server> serverMockedStatic;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp()
|
||||||
|
throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||||
connection = mock(LobbyConnection.class);
|
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
|
@Test
|
||||||
void lobbyGetsStartedTest() {
|
void canAddLobbyTest() {
|
||||||
|
assertThat(lobbyRunner.canAddLobby()).isTrue();
|
||||||
|
lobbyRunner.startLobby(connection);
|
||||||
|
assertThat(lobbyRunner.canAddLobby()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void removeLobbyRemovesLobbyAndSetsTerminationFlag() {
|
||||||
|
lobbyRunner.startLobby(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user