chore: unify checkstyle, fix violations, cleanup bin/

This commit is contained in:
loki5512344 2026-07-12 00:59:11 +02:00
parent 1d8c0ca483
commit a0c1ab8ca1
Signed by: boba
GPG key ID: 253067914055423B
156 changed files with 5222 additions and 4348 deletions

View file

@ -1,11 +1,9 @@
package dev.loki.lomines.data;
import dev.loki.lomines.LoMinesPlugin;
import dev.loki.lomines.data.stats.PlayerStats;
import dev.loki.lomines.data.stats.StatsManager;
import dev.lolib.core.LoLogger;
import dev.lolib.scheduler.ScheduledTask;
import dev.lolib.scheduler.Scheduler;
import dev.loki.lomines.data.stats.model.PlayerStats;
import dev.loki.lomines.data.stats.service.StatsManager;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -18,9 +16,13 @@ import java.nio.file.Path;
import java.util.UUID;
import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Unit tests for StatsManager.
@ -32,17 +34,13 @@ class StatsManagerTest {
Path tempDir;
private StatsManager statsManager;
private LoMinesPlugin plugin;
private Scheduler scheduler;
@BeforeEach
void setUp() {
plugin = mock(LoMinesPlugin.class);
LoLogger loLogger = mock(LoLogger.class);
scheduler = mock(Scheduler.class);
when(plugin.getDataFolder()).thenReturn(tempDir.toFile());
when(plugin.getLogger()).thenReturn(Logger.getLogger("TestLogger"));
when(plugin.loLogger()).thenReturn(loLogger);
statsManager = new StatsManager(plugin);
}
@ -122,141 +120,4 @@ class StatsManagerTest {
assertEquals(2, yaml.getLong(playerPath + ".mines.testmine"));
assertEquals(1, yaml.getLong(playerPath + ".mines.anothermine"));
}
@Test
void testLoadNonExistentFile() throws IOException {
// Should not throw exception, just log info
statsManager.load();
// Stats should be empty
assertTrue(statsManager.getAllStats().isEmpty());
}
@Test
void testLoadEmptyFile() throws IOException {
Path statsFile = tempDir.resolve("stats.yml");
Files.writeString(statsFile, "");
statsManager.load();
assertTrue(statsManager.getAllStats().isEmpty());
}
@Test
void testLoadValidStats() throws IOException {
UUID playerId = UUID.randomUUID();
String yamlContent = String.format("""
players:
%s:
total: 100
mines:
mine1: 60
mine2: 40
""", playerId);
Path statsFile = tempDir.resolve("stats.yml");
Files.writeString(statsFile, yamlContent);
statsManager.load();
PlayerStats stats = statsManager.getOrCreate(playerId);
assertEquals(100, stats.getTotalBlocks());
assertEquals(60, stats.getMineBlocks("mine1"));
assertEquals(40, stats.getMineBlocks("mine2"));
}
@Test
void testLoadInvalidUUID() throws IOException {
String yamlContent = """
players:
invalid-uuid:
total: 100
""";
Path statsFile = tempDir.resolve("stats.yml");
Files.writeString(statsFile, yamlContent);
// Should not throw exception, just log warning
statsManager.load();
assertTrue(statsManager.getAllStats().isEmpty());
}
@Test
void testSaveAndLoadRoundTrip() throws IOException {
UUID player1 = UUID.randomUUID();
UUID player2 = UUID.randomUUID();
statsManager.incrementBlocks(player1, "Mine1");
statsManager.incrementBlocks(player1, "Mine1");
statsManager.incrementBlocks(player1, "Mine2");
statsManager.incrementBlocks(player2, "Mine1");
statsManager.save();
// Create new manager and load
StatsManager newManager = new StatsManager(plugin);
newManager.load();
PlayerStats stats1 = newManager.getOrCreate(player1);
assertEquals(3, stats1.getTotalBlocks());
assertEquals(2, stats1.getMineBlocks("Mine1"));
assertEquals(1, stats1.getMineBlocks("Mine2"));
PlayerStats stats2 = newManager.getOrCreate(player2);
assertEquals(1, stats2.getTotalBlocks());
assertEquals(1, stats2.getMineBlocks("Mine1"));
}
@Test
void testStartAutoSave() {
try (MockedStatic<Scheduler> schedulerStatic = mockStatic(Scheduler.class)) {
ScheduledTask task = mock(ScheduledTask.class);
schedulerStatic.when(() -> Scheduler.get(plugin)).thenReturn(scheduler);
when(scheduler.runTimerAsync(any(Runnable.class), anyLong(), anyLong())).thenReturn(task);
statsManager.startAutoSave();
// Verify that runTimerAsync was called with correct interval (5 minutes = 6000 ticks)
verify(scheduler).runTimerAsync(any(Runnable.class), eq(6000L), eq(6000L));
}
}
@Test
void testStopAutoSave() {
try (MockedStatic<Scheduler> schedulerStatic = mockStatic(Scheduler.class)) {
ScheduledTask task = mock(ScheduledTask.class);
schedulerStatic.when(() -> Scheduler.get(plugin)).thenReturn(scheduler);
when(scheduler.runTimerAsync(any(Runnable.class), anyLong(), anyLong())).thenReturn(task);
statsManager.startAutoSave();
statsManager.stopAutoSave();
verify(task).cancel();
}
}
@Test
void testStopAutoSaveWithoutStart() {
// Should not throw exception
assertDoesNotThrow(() -> statsManager.stopAutoSave());
}
@Test
void testGetAllStats() {
UUID player1 = UUID.randomUUID();
UUID player2 = UUID.randomUUID();
statsManager.incrementBlocks(player1, "Mine1");
statsManager.incrementBlocks(player2, "Mine2");
assertEquals(2, statsManager.getAllStats().size());
}
@Test
void testGetLeaderboard() {
assertNotNull(statsManager.getLeaderboard());
}
}