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