test: created test for RequestGameStateSegment

This commit is contained in:
Richard Reiber 2021-06-05 22:39:40 +02:00
parent a61409a822
commit 9fcb1aa009

View File

@ -0,0 +1,45 @@
package uulm.teamname.marvelous.server.lobby.pipelining;
import org.junit.jupiter.api.Test;
import uulm.teamname.marvelous.gamelibrary.events.Event;
import uulm.teamname.marvelous.gamelibrary.events.GamestateEvent;
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
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.Participant;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
class RequestGameStateSegmentTest {
@Test
void requestGamestateTest(){
var game = mock(GameInstance.class);
var gamestateEvent = mock(GamestateEvent.class);
var segment = new RequestGameStateSegment(game);
var requests = new Request[]{
new RequestBuilder(RequestType.Req).buildGameRequest(),
new RequestBuilder(RequestType.DisconnectRequest).buildGameRequest()
};
var participant = mock(Participant.class);
var packet = new Packet(requests, participant);
when(game.getGameStateEvent()).thenReturn(gamestateEvent);
AtomicBoolean abort = new AtomicBoolean(false);
List<Event> carrier = new ArrayList<>();
segment.processRequests(packet, carrier, abort);
assertThat(packet).isEmpty();
assertThat(carrier).containsOnly(gamestateEvent);
verify(game).getGameStateEvent();
}
}