test: created test for Pipeline
This commit is contained in:
parent
b4d547a6d3
commit
a61409a822
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user