refactor: changed class names to reflect their uses better
This commit is contained in:
parent
f0a4cd0adb
commit
6a0bef616f
@ -2,22 +2,23 @@ package uulm.teamname.marvelous.server.lobby;
|
||||
|
||||
import org.tinylog.Logger;
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
||||
import uulm.teamname.marvelous.server.Server;
|
||||
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* The {@link TurnTimer} class is called by the {@link Lobby} to limit the amount of time a player has per round.
|
||||
* The {@link TimeoutTimer} class is called by the {@link Lobby} to limit the amount of time a player has per round.
|
||||
*/
|
||||
public class TurnTimer {
|
||||
public class TimeoutTimer {
|
||||
private final ScheduledExecutorService timer;
|
||||
private final Consumer<Participant> callback;
|
||||
private final int maxRoundTime;
|
||||
|
||||
private ScheduledFuture<Participant> current;
|
||||
|
||||
public TurnTimer(int maxRoundTime, Consumer<Participant> callback) {
|
||||
public TimeoutTimer(int maxRoundTime, Consumer<Participant> callback) {
|
||||
String lobbyThreadName = Thread.currentThread().getName();
|
||||
ThreadFactory threadFactory = new ThreadFactory() {
|
||||
@Override
|
||||
@ -26,7 +27,7 @@ public class TurnTimer {
|
||||
}
|
||||
};
|
||||
this.timer = Executors.newSingleThreadScheduledExecutor(threadFactory);
|
||||
this.maxRoundTime = 3;
|
||||
this.maxRoundTime = Server.getPartyConfig().maxRoundTime;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
@ -4,30 +4,28 @@ import org.java_websocket.WebSocket;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
|
||||
import uulm.teamname.marvelous.server.lobbymanager.LobbyConnection;
|
||||
import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
||||
import uulm.teamname.marvelous.server.netconnector.Client;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class TurnTimerTest {
|
||||
TurnTimer turnTimer;
|
||||
class TimeoutTimerTest {
|
||||
TimeoutTimer timeoutTimer;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach(){
|
||||
var callback = mock(Consumer.class);
|
||||
turnTimer = new TurnTimer(20, callback);
|
||||
timeoutTimer = new TimeoutTimer(20, callback);
|
||||
}
|
||||
|
||||
@Test
|
||||
void startTurnTimerTest(){
|
||||
var connection = mock(WebSocket.class);
|
||||
var participant = new Participant(new Client(connection), "lobby", ParticipantType.Spectator);
|
||||
assertThatIllegalStateException().describedAs("Spectators don't have TurnTime").isThrownBy(() -> turnTimer.startTurnTimer(participant));
|
||||
assertThatIllegalStateException().describedAs("Spectators don't have TurnTime").isThrownBy(() -> timeoutTimer.startTurnTimer(participant));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user