refactor: changed class names to reflect their uses better

This commit is contained in:
Yannik Bretschneider 2021-06-07 16:42:19 +02:00
parent f0a4cd0adb
commit 6a0bef616f
5 changed files with 9 additions and 10 deletions

View File

@ -2,22 +2,23 @@ package uulm.teamname.marvelous.server.lobby;
import org.tinylog.Logger; import org.tinylog.Logger;
import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType; import uulm.teamname.marvelous.gamelibrary.messages.ParticipantType;
import uulm.teamname.marvelous.server.Server;
import uulm.teamname.marvelous.server.lobbymanager.Participant; import uulm.teamname.marvelous.server.lobbymanager.Participant;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.function.Consumer; 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 ScheduledExecutorService timer;
private final Consumer<Participant> callback; private final Consumer<Participant> callback;
private final int maxRoundTime; private final int maxRoundTime;
private ScheduledFuture<Participant> current; private ScheduledFuture<Participant> current;
public TurnTimer(int maxRoundTime, Consumer<Participant> callback) { public TimeoutTimer(int maxRoundTime, Consumer<Participant> callback) {
String lobbyThreadName = Thread.currentThread().getName(); String lobbyThreadName = Thread.currentThread().getName();
ThreadFactory threadFactory = new ThreadFactory() { ThreadFactory threadFactory = new ThreadFactory() {
@Override @Override
@ -26,7 +27,7 @@ public class TurnTimer {
} }
}; };
this.timer = Executors.newSingleThreadScheduledExecutor(threadFactory); this.timer = Executors.newSingleThreadScheduledExecutor(threadFactory);
this.maxRoundTime = 3; this.maxRoundTime = Server.getPartyConfig().maxRoundTime;
this.callback = callback; this.callback = callback;
} }

View File

@ -4,30 +4,28 @@ import org.java_websocket.WebSocket;
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.messages.ParticipantType;
import uulm.teamname.marvelous.server.lobbymanager.LobbyConnection;
import uulm.teamname.marvelous.server.lobbymanager.Participant; import uulm.teamname.marvelous.server.lobbymanager.Participant;
import uulm.teamname.marvelous.server.netconnector.Client; import uulm.teamname.marvelous.server.netconnector.Client;
import java.util.function.Consumer; import java.util.function.Consumer;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
class TurnTimerTest { class TimeoutTimerTest {
TurnTimer turnTimer; TimeoutTimer timeoutTimer;
@BeforeEach @BeforeEach
void beforeEach(){ void beforeEach(){
var callback = mock(Consumer.class); var callback = mock(Consumer.class);
turnTimer = new TurnTimer(20, callback); timeoutTimer = new TimeoutTimer(20, callback);
} }
@Test @Test
void startTurnTimerTest(){ void startTurnTimerTest(){
var connection = mock(WebSocket.class); var connection = mock(WebSocket.class);
var participant = new Participant(new Client(connection), "lobby", ParticipantType.Spectator); 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));
} }
} }