From 8ee3e22dab82b0848fb2c5bd7835aa97d4b38e14 Mon Sep 17 00:00:00 2001 From: Richard Reiber Date: Sat, 5 Jun 2021 21:17:51 +0200 Subject: [PATCH] test: added processRequests-Tests to PauseSegmentTest --- .../lobby/pipelining/PauseSegmentTest.java | 71 ++++++++++++++++++- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegmentTest.java b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegmentTest.java index 0758382..534b4a7 100644 --- a/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegmentTest.java +++ b/Server/src/test/java/uulm/teamname/marvelous/server/lobby/pipelining/PauseSegmentTest.java @@ -2,7 +2,18 @@ package uulm.teamname.marvelous.server.lobby.pipelining; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; +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.LobbyConnection; +import uulm.teamname.marvelous.server.lobbymanager.Participant; + +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; + import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.mock; class PauseSegmentTest { @@ -34,8 +45,62 @@ class PauseSegmentTest { } @Test - void processEvents() { - // TODO: check that events get pipelined normally if not paused, but filtered if paused - // and check that events work properly + void doNotProcessEventsIfStopped() { + var requests = new Request[]{ + new RequestBuilder(RequestType.PauseStartRequest).buildGameRequest(), + new RequestBuilder(RequestType.Req).buildGameRequest(), + new RequestBuilder(RequestType.DisconnectRequest).buildGameRequest(), + new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest(), + new RequestBuilder(RequestType.MoveRequest).buildGameRequest() + }; + var participant = mock(Participant.class); + var packet = new Packet(requests, participant); + AtomicBoolean abort = new AtomicBoolean(false); + pauseSegment.processRequests(packet, new ArrayList<>(), abort); + assertThat(packet).containsOnly(new RequestBuilder(RequestType.Req).buildGameRequest(), new RequestBuilder(RequestType.DisconnectRequest).buildGameRequest()); + } + + @Test + void doProcessEventsIfNotStopped(){ + var requests = new Request[]{ + new RequestBuilder(RequestType.PauseStopRequest).buildGameRequest(), + new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest(), + new RequestBuilder(RequestType.MoveRequest).buildGameRequest() + }; + var participant = mock(Participant.class); + var packet = new Packet(requests, participant); + AtomicBoolean abort = new AtomicBoolean(false); + pauseSegment.pauseGame(); + pauseSegment.processRequests(packet, new ArrayList<>(), abort); + assertThat(packet).containsOnly( + new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest(), + new RequestBuilder(RequestType.MoveRequest).buildGameRequest() + ); + } + + @Test + void pauseRequestWhilePaused(){ + var requests = new Request[]{ + new RequestBuilder(RequestType.PauseStartRequest).buildGameRequest(), + }; + var participant = mock(Participant.class); + var packet = new Packet(requests, participant); + AtomicBoolean abort = new AtomicBoolean(false); + pauseSegment.pauseGame(); + pauseSegment.processRequests(packet, new ArrayList<>(), abort); + assertThat(abort.get()).isTrue(); + } + + @Test + void unpauseRequestWhenNotPaused(){ + var requests = new Request[]{ + new RequestBuilder(RequestType.PauseStopRequest).buildGameRequest(), + }; + var participant = mock(Participant.class); + var packet = new Packet(requests, participant); + AtomicBoolean abort = new AtomicBoolean(false); + pauseSegment.pauseEnd(); + pauseSegment.processRequests(packet, new ArrayList<>(), abort); + assertThat(abort.get()).isTrue(); } } \ No newline at end of file