67 lines
2.2 KiB
Java
67 lines
2.2 KiB
Java
package uulm.teamname.marvelous.server.lobby.pipelining;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
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.lobbymanager.Participant;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
import static org.mockito.Mockito.*;
|
|
import static org.assertj.core.api.Assertions.*;
|
|
|
|
class FilterEndRoundRequestSegmentTest {
|
|
|
|
FilterEndRoundRequestSegment segment;
|
|
|
|
Participant activeParticipant;
|
|
|
|
Request[] requests;
|
|
|
|
@BeforeEach
|
|
void beforeEach() {
|
|
this.segment = new FilterEndRoundRequestSegment(this::getActiveParticipant);
|
|
this.activeParticipant = mock(Participant.class);
|
|
requests = new Request[] {
|
|
new RequestBuilder(RequestType.EndRoundRequest).buildGameRequest()
|
|
};
|
|
}
|
|
|
|
private Participant getActiveParticipant() {
|
|
return activeParticipant;
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Request from active participant doesn't get filtered")
|
|
void packetFromActiveParticipantTest() {
|
|
var packet = new Packet(requests, activeParticipant);
|
|
var atomicBoolean = new AtomicBoolean(false);
|
|
|
|
var processedPacket = (Packet) packet.clone();
|
|
segment.processRequests(processedPacket, new ArrayList<>(), atomicBoolean);
|
|
|
|
assertThat(processedPacket).isEqualTo(packet);
|
|
assertThat(atomicBoolean.get()).isFalse();
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Request from non-active participant gets flagged as an error")
|
|
void packetFromNonActiveParticipantTest() {
|
|
var packet = new Packet(requests, mock(Participant.class));
|
|
var atomicBoolean = new AtomicBoolean(false);
|
|
|
|
var processedPacket = (Packet) packet.clone();
|
|
segment.processRequests(processedPacket, new ArrayList<>(), atomicBoolean);
|
|
|
|
// assertThat(processedPacket).isEqualTo(packet); is not necessary as there's no actual filtering going on
|
|
assertThat(atomicBoolean.get()).isTrue();
|
|
}
|
|
|
|
|
|
|
|
}
|