146 lines
4.4 KiB
Java
146 lines
4.4 KiB
Java
package games.dmg.spigottyrant;
|
|
|
|
import static org.mockito.Mockito.clearInvocations;
|
|
import static org.mockito.Mockito.doReturn;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.verify;
|
|
import static org.mockito.Mockito.verifyNoInteractions;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import java.nio.file.Path;
|
|
import java.time.Clock;
|
|
import java.time.Instant;
|
|
import java.time.ZoneOffset;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import java.util.Set;
|
|
import java.util.UUID;
|
|
import java.util.logging.Logger;
|
|
import org.bukkit.Server;
|
|
import org.bukkit.entity.Player;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
final class AssassinEffectControllerTest {
|
|
private static final Instant NOW = Instant.parse("2026-08-18T12:00:00Z");
|
|
private static final UUID PLAYER_ID = UUID.fromString(
|
|
"11111111-1111-1111-1111-111111111111"
|
|
);
|
|
|
|
@TempDir
|
|
Path temporaryDirectory;
|
|
|
|
@Test
|
|
void doesNotRemovePotionEffectsItDidNotApply() throws Exception {
|
|
TyrantStateManager stateManager = manager();
|
|
Player player = player();
|
|
Server server = server(player);
|
|
AssassinEffectController.EffectApplier effects = mock(
|
|
AssassinEffectController.EffectApplier.class
|
|
);
|
|
AssassinEffectController controller = controller(stateManager, server, effects);
|
|
|
|
controller.run();
|
|
controller.clearAll();
|
|
|
|
verifyNoInteractions(effects);
|
|
}
|
|
|
|
@Test
|
|
void stopsRefreshingManagedInvisibilityAfterItsDeadline() throws Exception {
|
|
TyrantStateManager stateManager = manager();
|
|
stateManager.updateGame(ignored -> runningGame());
|
|
stateManager.updatePlayer(PLAYER_ID, "Assassin", ignored -> assassin(Map.of(
|
|
Ability.ASSASSIN_INVISIBILITY_ACTIVE, NOW.plusSeconds(60),
|
|
Ability.ASSASSIN_DOUBLE_JUMP, NOW.plusSeconds(60)
|
|
)));
|
|
Player player = player();
|
|
Server server = server(player);
|
|
AssassinEffectController.EffectApplier effects = mock(
|
|
AssassinEffectController.EffectApplier.class
|
|
);
|
|
AssassinEffectController controller = controller(stateManager, server, effects);
|
|
|
|
controller.run();
|
|
|
|
verify(effects).apply(
|
|
player,
|
|
AssassinEffectController.EffectKind.INVISIBILITY,
|
|
0,
|
|
false
|
|
);
|
|
|
|
stateManager.updatePlayer(PLAYER_ID, "Assassin", ignored -> assassin(Map.of(
|
|
Ability.ASSASSIN_DOUBLE_JUMP, NOW.plusSeconds(60)
|
|
)));
|
|
clearInvocations(player, effects);
|
|
controller.run();
|
|
|
|
verifyNoInteractions(effects);
|
|
}
|
|
|
|
private TyrantStateManager manager() throws Exception {
|
|
return new TyrantStateManager(
|
|
new YamlTyrantStateRepository(temporaryDirectory.resolve("state.yml")),
|
|
Logger.getLogger("test")
|
|
);
|
|
}
|
|
|
|
private static AssassinEffectController controller(
|
|
TyrantStateManager stateManager,
|
|
Server server,
|
|
AssassinEffectController.EffectApplier effects
|
|
) {
|
|
return new AssassinEffectController(
|
|
stateManager,
|
|
server,
|
|
PluginSettings.from(Map.of()),
|
|
Clock.fixed(NOW, ZoneOffset.UTC),
|
|
effects
|
|
);
|
|
}
|
|
|
|
private static Server server(Player player) {
|
|
Server server = mock(Server.class);
|
|
doReturn(List.of(player)).when(server).getOnlinePlayers();
|
|
return server;
|
|
}
|
|
|
|
private static Player player() {
|
|
Player player = mock(Player.class);
|
|
when(player.getUniqueId()).thenReturn(PLAYER_ID);
|
|
when(player.getName()).thenReturn("Assassin");
|
|
return player;
|
|
}
|
|
|
|
private static PlayerState assassin(Map<Ability, Instant> cooldowns) {
|
|
return new PlayerState(
|
|
PLAYER_ID,
|
|
"Assassin",
|
|
Optional.empty(),
|
|
Optional.empty(),
|
|
TyrantClass.ASSASSIN,
|
|
Optional.empty(),
|
|
cooldowns,
|
|
Set.of(),
|
|
List.of()
|
|
);
|
|
}
|
|
|
|
private static GameState runningGame() {
|
|
return new GameState(
|
|
GameLifecycle.RUNNING,
|
|
Optional.empty(),
|
|
Optional.empty(),
|
|
Optional.empty(),
|
|
Optional.empty(),
|
|
Optional.empty(),
|
|
java.time.Duration.ZERO,
|
|
0,
|
|
0,
|
|
Set.of()
|
|
);
|
|
}
|
|
}
|