diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegmentTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegmentTest.java new file mode 100644 index 0000000..55a9076 --- /dev/null +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegmentTest.java @@ -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 carrier = new ArrayList<>(); + + segment.processRequests(packet, carrier, abort); + assertThat(packet).isEmpty(); + assertThat(carrier).containsOnly(gamestateEvent); + verify(game).getGameStateEvent(); + } + +} \ No newline at end of file