diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PipelineTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PipelineTest.java new file mode 100644 index 0000000..c35ccda --- /dev/null +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PipelineTest.java @@ -0,0 +1,66 @@ +package uulm.teamname.marvelous.server.lobby.pipelining; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +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.lobby.Lobby; +import uulm.teamname.marvelous.server.lobbymanager.Participant; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.*; + +class PipelineTest { + Pipeline pipeline; + @BeforeEach + void beforeEach(){ + pipeline = new Pipeline(); + } + + @Test + void addSegmentsTest(){ + Lobby lobby = mock(Lobby.class); + PauseSegment pauseSegment = new PauseSegment(); + DisconnectSegment disconnectSegment = new DisconnectSegment(lobby); + pipeline.addSegment(pauseSegment); + assertThat(pipeline.contains(pauseSegment)).isTrue(); + assertThat(pipeline.contains(disconnectSegment)).isFalse(); + pipeline.addSegment(disconnectSegment); + assertThat(pipeline.contains(pauseSegment)).isTrue(); + assertThat(pipeline.contains(disconnectSegment)).isTrue(); + } + + @Test + void processRequestTest(){ + var segment = mock(Segment.class); + var segment2 = mock(Segment.class); + var segment3 = mock(Segment.class); + + var requests = new Request[]{ + new RequestBuilder(RequestType.PauseStartRequest).buildGameRequest(), + new RequestBuilder(RequestType.Req).buildGameRequest() + }; + + Participant participant = mock(Participant.class); + + var abort = new AtomicBoolean(false); + + Packet packet = new Packet(requests, participant); + + pipeline.addSegment(segment) + .addSegment(segment2) + .addSegment(segment3); + + pipeline.processRequests(requests, participant); + verify(segment).processRequests(eq(packet), eq(new ArrayList<>()), any(AtomicBoolean.class)); + verify(segment2).processRequests(eq(packet), eq(new ArrayList<>()), any(AtomicBoolean.class)); + verify(segment3).processRequests(eq(packet), eq(new ArrayList<>()), any(AtomicBoolean.class)); + } +} \ No newline at end of file