From 9fcb1aa00979c9665a407fbbe5a4684041e30e83 Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Sat, 5 Jun 2021 22:39:40 +0200 Subject: [PATCH] test: created test for RequestGameStateSegment --- .../RequestGameStateSegmentTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/RequestGameStateSegmentTest.java 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