77 lines
3.1 KiB
Java
77 lines
3.1 KiB
Java
package games.dmg.spigottyrant;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import java.time.Duration;
|
|
import java.time.Instant;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
final class ParticipationServiceTest {
|
|
private static final UUID PLAYER = UUID.fromString("11111111-1111-1111-1111-111111111111");
|
|
private static final UUID TYRANT = UUID.fromString("22222222-2222-2222-2222-222222222222");
|
|
private static final Instant NOW = Instant.parse("2026-08-14T12:00:00Z");
|
|
private final ParticipationService service = new ParticipationService(Duration.ofDays(7));
|
|
|
|
@Test
|
|
void optingOutClearsOrdinaryClassAndFollowerButKeepsPlayerOutAfterCooldown() {
|
|
PlayerState assigned = new PlayerState(
|
|
PLAYER, "Player", Optional.of(NOW), Optional.empty(), TyrantClass.ASSASSIN,
|
|
Optional.of(UUID.randomUUID()),
|
|
Map.of(Ability.ASSASSIN_INVISIBILITY, NOW.plusSeconds(30)),
|
|
Set.of(Ability.ASSASSIN_INVISIBILITY), java.util.List.of()
|
|
);
|
|
GameState game = runningGame();
|
|
|
|
ParticipationResult result = service.optOut(game, assigned, NOW);
|
|
|
|
assertEquals(ParticipationStatus.OPTED_OUT, result.status());
|
|
assertEquals(Optional.of(NOW.plus(Duration.ofDays(7))),
|
|
result.player().optedOutUntil());
|
|
assertEquals(TyrantClass.NONE, result.player().tyrantClass());
|
|
assertEquals(Optional.empty(), result.player().followerOf());
|
|
assertEquals(Map.of(), result.player().cooldownEnds());
|
|
assertEquals(ParticipationStatus.OPTED_OUT,
|
|
service.status(result.player(), NOW.plus(Duration.ofDays(8))));
|
|
}
|
|
|
|
@Test
|
|
void optingBackInIsBlockedUntilSevenDaysAndThenClearsOptOut() {
|
|
PlayerState player = service.optOut(
|
|
runningGame(), PlayerState.newPlayer(PLAYER, "Player"), NOW
|
|
).player();
|
|
|
|
ParticipationResult early = service.optIn(player, NOW.plus(Duration.ofDays(6)));
|
|
ParticipationResult ready = service.optIn(player, NOW.plus(Duration.ofDays(7)));
|
|
|
|
assertEquals(ParticipationStatus.COOLDOWN_ACTIVE, early.status());
|
|
assertEquals(ParticipationStatus.OPTED_IN, ready.status());
|
|
assertEquals(Optional.empty(), ready.player().optedOutUntil());
|
|
}
|
|
|
|
@Test
|
|
void currentCentralRoleMustRelinquishBeforeOptingOut() {
|
|
GameState game = new GameState(
|
|
GameLifecycle.RUNNING, Optional.of(PLAYER), Optional.empty(), Optional.empty(),
|
|
Optional.empty(), Optional.empty(), Duration.ZERO, 0, 1, Set.of()
|
|
);
|
|
|
|
ParticipationResult result = service.optOut(
|
|
game, PlayerState.newPlayer(PLAYER, "Tyrant"), NOW
|
|
);
|
|
|
|
assertEquals(ParticipationStatus.MUST_RELINQUISH_ROLE, result.status());
|
|
assertEquals(Optional.empty(), result.player().optedOutUntil());
|
|
}
|
|
|
|
private static GameState runningGame() {
|
|
return new GameState(
|
|
GameLifecycle.RUNNING, Optional.of(TYRANT), Optional.empty(), Optional.empty(),
|
|
Optional.empty(), Optional.empty(), Duration.ZERO, 0, 1, Set.of()
|
|
);
|
|
}
|
|
}
|