89 lines
2.8 KiB
Java
89 lines
2.8 KiB
Java
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.gamelibrary.messages.ParticipantType;
|
|
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<Server> serverMockedStatic;
|
|
|
|
@BeforeEach
|
|
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() throws InterruptedException {
|
|
lobbyRunner.startLobby(connection);
|
|
Thread.sleep(10);
|
|
verify(connection).run();
|
|
}
|
|
|
|
@Test
|
|
void canAddLobbyTest() throws InterruptedException {
|
|
assertThat(lobbyRunner.canAddLobby()).isTrue();
|
|
lobbyRunner.startLobby(connection);
|
|
assertThat(lobbyRunner.canAddLobby()).isFalse();
|
|
}
|
|
|
|
@Test
|
|
void removeLobbyRemovesLobbyAndSetsTerminationFlag() {
|
|
lobbyRunner.startLobby(connection);
|
|
}
|
|
|
|
@Test
|
|
void lobbyIsStartedTest() {
|
|
connection = spy(new LobbyConnection("SomeGameID", null, null));
|
|
doNothing().when(connection).run();
|
|
assertThat(lobbyRunner.isStarted(connection)).isFalse();
|
|
|
|
lobbyRunner.startLobby(connection);
|
|
assertThat(lobbyRunner.isStarted(connection)).isTrue();
|
|
|
|
connection.addSpectator(new Participant(null, ParticipantType.Spectator, "Hi"));
|
|
connection.addSpectator(new Participant(null, ParticipantType.Spectator, "Hi2"));
|
|
connection.removeParticipant(new Participant(null, ParticipantType.Spectator, "Hi"));
|
|
assertThat(lobbyRunner.isStarted(connection)).isTrue();
|
|
|
|
lobbyRunner.removeLobby(connection);
|
|
assertThat(lobbyRunner.isStarted(connection)).isFalse();
|
|
}
|
|
*/
|
|
}
|