test: added TimeoutWarning and generateWin tests

This commit is contained in:
Richard Reiber 2021-06-06 00:49:53 +02:00
parent c1cd3fba66
commit 7f512400df

View File

@ -8,6 +8,8 @@ import uulm.teamname.marvelous.gamelibrary.config.FieldType;
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig; import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.entities.EntityType; import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
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.messages.ParticipantType;
import uulm.teamname.marvelous.gamelibrary.requests.Request; import uulm.teamname.marvelous.gamelibrary.requests.Request;
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder; import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
@ -57,4 +59,40 @@ class LobbyTest {
lobby.receiveRequests(requests, playerOne); lobby.receiveRequests(requests, playerOne);
} }
@Test
void soonTimeoutTest(){
var participant = mock(Participant.class);
lobby.soonTimeout(participant);
verify(connection).sendEvents(participant, new EventBuilder(EventType.TimeoutWarningEvent).buildGameStateEvent());
}
@Test
void generateWinPlayer1Test(){
var webSoc = mock(WebSocket.class);
Participant winner = new Participant(webSoc, ParticipantType.PlayerOne, "playerOne");
lobby.generateWin(winner);
verify(connection).broadcastEvents(
new EventBuilder(EventType.WinEvent)
.withPlayerWon(1)
.buildGameStateEvent(),
new EventBuilder(EventType.DisconnectEvent)
.buildGameStateEvent());
verify(connection).terminateConnection();
}
@Test
void generateWinPlayer2Test(){
var webSoc = mock(WebSocket.class);
Participant winner = new Participant(webSoc, ParticipantType.PlayerOne, "playerOne");
lobby.generateWin(winner);
verify(connection).broadcastEvents(
new EventBuilder(EventType.WinEvent)
.withPlayerWon(2)
.buildGameStateEvent(),
new EventBuilder(EventType.DisconnectEvent)
.buildGameStateEvent());
verify(connection).terminateConnection();
}
} }