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 java.util.random.RandomGenerator; import org.junit.jupiter.api.Test; final class RoleRelinquishmentServiceTest { @Test void vigilanteCanRelinquishAndTriggerNormalReroll() { UUID tyrant = UUID.fromString("11111111-1111-1111-1111-111111111111"); UUID vigilante = UUID.fromString("22222222-2222-2222-2222-222222222222"); UUID candidate = UUID.fromString("33333333-3333-3333-3333-333333333333"); Instant now = Instant.parse("2026-08-14T12:00:00Z"); RoleCandidateSelector selector = new RoleCandidateSelector(); RandomGenerator random = RandomGenerator.of("L64X128MixRandom"); TyrantSuccessionService succession = new TyrantSuccessionService( selector, Duration.ofHours(24), Duration.ofHours(24), random ); RoleMaintenanceService maintenance = new RoleMaintenanceService( selector, succession, Duration.ofHours(48), Duration.ofHours(24), Duration.ofHours(24), random ); RoleRelinquishmentService service = new RoleRelinquishmentService( succession, maintenance ); GameState game = new GameState( GameLifecycle.RUNNING, Optional.of(tyrant), Optional.of(vigilante), Optional.empty(), Optional.empty(), Optional.empty(), Duration.ZERO, 0, 0, Set.of() ); PlayerState tyrantState = active(tyrant, now); PlayerState vigilanteState = active(vigilante, now); PlayerState candidateState = active(candidate, now); RelinquishmentResult result = service.relinquish( new PersistentState(game, Map.of( tyrant, tyrantState, vigilante, vigilanteState, candidate, candidateState )), vigilante, Set.of(tyrant, candidate), now ); assertEquals(RelinquishmentStatus.RELINQUISHED, result.status()); assertEquals(Optional.of(candidate), result.state().game().vigilanteId()); } private static PlayerState active(UUID id, Instant now) { PlayerState player = PlayerState.newPlayer(id, id.toString()); return new PlayerState( id, player.latestName(), Optional.of(now.minusSeconds(60)), Optional.empty(), TyrantClass.NONE, Optional.empty(), Map.of(), Set.of(), java.util.List.of() ); } }