111 lines
4.0 KiB
Java
111 lines
4.0 KiB
Java
package uulm.teamname.marvelous.server.lobby;
|
|
|
|
import org.java_websocket.WebSocket;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Disabled;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.Mock;
|
|
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
|
|
import uulm.teamname.marvelous.gamelibrary.config.FieldType;
|
|
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
|
|
import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
|
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
|
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
|
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
|
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
|
import uulm.teamname.marvelous.server.lobbymanager.LobbyConnection;
|
|
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
|
import uulm.teamname.marvelous.server.netconnector.Client;
|
|
|
|
import java.util.List;
|
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
class LobbyTest {
|
|
|
|
@Mock
|
|
|
|
Lobby lobby;
|
|
LobbyConnection connection;
|
|
|
|
@BeforeEach
|
|
void beforeEach(){
|
|
var gameID = "GameID";
|
|
connection = mock(LobbyConnection.class);
|
|
var partyConfig = mock(PartyConfig.class);
|
|
var scenarioConfig = new ScenarioConfig();
|
|
scenarioConfig.scenario = new FieldType[][] {
|
|
{FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS},
|
|
{FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS, FieldType.GRASS}
|
|
};
|
|
var characterConfig = mock(CharacterConfig.class);
|
|
|
|
lobby = spy(new Lobby(
|
|
gameID,
|
|
connection,
|
|
partyConfig,
|
|
characterConfig,
|
|
scenarioConfig,
|
|
List.of(1, 2, 3, 4, 5, 6),
|
|
List.of(7, 8, 9, 10, 11, 12)
|
|
));
|
|
}
|
|
|
|
@Test
|
|
@Disabled
|
|
void receiveRequestsTest(){
|
|
var requests = new Request[] {
|
|
new RequestBuilder(RequestType.Req).buildGameRequest(),
|
|
new RequestBuilder(RequestType.MoveRequest).buildGameRequest()
|
|
};
|
|
var playerConnection = mock(WebSocket.class);
|
|
doNothing().when(lobby).updateTurnTimer();
|
|
|
|
Participant playerOne = new Participant(
|
|
new Client(playerConnection), "LobbyOne", ParticipantType.PlayerOne, false);
|
|
lobby.receiveRequests(requests, playerOne);
|
|
}
|
|
|
|
@Test
|
|
@Disabled
|
|
void soonTimeoutTest(){
|
|
var participant = mock(Participant.class);
|
|
lobby.soonTimeout(participant, 15);
|
|
verify(connection).sendEvents(participant, new EventBuilder(EventType.TimeoutWarningEvent).buildGameStateEvent());
|
|
}
|
|
|
|
@Test
|
|
@Disabled
|
|
void generateWinPlayer1Test(){
|
|
var webSoc = mock(WebSocket.class);
|
|
Participant winner = new Participant(new Client(webSoc), "someLobby", ParticipantType.PlayerOne, false);
|
|
lobby.triggerWin(winner);
|
|
verify(connection).broadcastEvents(
|
|
new EventBuilder(EventType.WinEvent)
|
|
.withPlayerWon(1)
|
|
.buildGameStateEvent(),
|
|
new EventBuilder(EventType.DisconnectEvent)
|
|
.buildGameStateEvent());
|
|
verify(connection).terminate();
|
|
}
|
|
|
|
@Test
|
|
@Disabled
|
|
void generateWinPlayer2Test(){
|
|
var webSoc = mock(WebSocket.class);
|
|
Participant winner = new Participant(new Client(webSoc), "someLobby", ParticipantType.PlayerOne, false);
|
|
lobby.triggerWin(winner);
|
|
verify(connection).broadcastEvents(
|
|
new EventBuilder(EventType.WinEvent)
|
|
.withPlayerWon(2)
|
|
.buildGameStateEvent(),
|
|
new EventBuilder(EventType.DisconnectEvent)
|
|
.buildGameStateEvent());
|
|
verify(connection).terminate();
|
|
}
|
|
|
|
|
|
}
|