test: added processRequests-Tests to PauseSegmentTest
This commit is contained in:
parent
3f14019a83
commit
8ee3e22dab
@ -2,7 +2,18 @@ package uulm.teamname.marvelous.server.lobby.pipelining;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
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.assertj.core.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
class PauseSegmentTest {
|
class PauseSegmentTest {
|
||||||
|
|
||||||
@ -34,8 +45,62 @@ class PauseSegmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void processEvents() {
|
void doNotProcessEventsIfStopped() {
|
||||||
// TODO: check that events get pipelined normally if not paused, but filtered if paused
|
var requests = new Request[]{
|
||||||
// and check that events work properly
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user