chore: rewrite ARCHITECTURE, enable tests via MockBukkit, checkstyle for tests, cleanup bin/libs

This commit is contained in:
loki5512344 2026-08-12 13:59:33 +02:00
parent a0c1ab8ca1
commit e8d516020c
Signed by: boba
GPG key ID: 253067914055423B
53 changed files with 1093 additions and 1410 deletions

View file

@ -12,9 +12,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doThrow;

View file

@ -10,41 +10,47 @@ import dev.loki.lomines.util.location.geo.Cuboid;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.when;
/**
* Unit tests for Mine class, specifically testing BlockSetter creation logic.
*/
@Disabled("Paper API RegistryAccess not available in unit tests")
class MineTest {
@Mock
private LoMinesPlugin plugin;
@Mock
private ServerMock server;
private World world;
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
when(world.getName()).thenReturn("world");
server = MockBukkit.mock();
server.addSimpleWorld("world");
world = server.getWorld("world");
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
}
@Test
void testCreateBlockSetter_WithOraxenPrefix_CreatesBukkitBlockSetter() {
void testCreateBlockSetterWithOraxenPrefixCreatesBukkitBlockSetter() {
// Oraxen integration is disabled — constructor throws IllegalArgumentException
Map<BlockKey, Double> blocks = new HashMap<>();
blocks.put(new BlockKey.Oraxen("custom_ore"), 50.0);
@ -59,7 +65,7 @@ class MineTest {
}
@Test
void testCreateBlockSetter_WithItemsAdderPrefix_CreatesBukkitBlockSetter() {
void testCreateBlockSetterWithItemsAdderPrefixCreatesBukkitBlockSetter() {
// ItemsAdder integration is disabled — constructor throws IllegalArgumentException
Map<BlockKey, Double> blocks = new HashMap<>();
blocks.put(new BlockKey.ItemsAdder("custom_block"), 60.0);
@ -73,7 +79,7 @@ class MineTest {
}
@Test
void testCreateBlockSetter_WithoutPrefix_CreatesBukkitBlockSetter() {
void testCreateBlockSetterWithoutPrefixCreatesBukkitBlockSetter() {
Map<BlockKey, Double> blocks = new HashMap<>();
blocks.put(new BlockKey.Vanilla(Material.STONE), 50.0);
blocks.put(new BlockKey.Vanilla(Material.COAL_ORE), 30.0);
@ -89,7 +95,7 @@ class MineTest {
}
@Test
void testCreateBlockSetter_WithEmptyBlocks_ThrowsException() {
void testCreateBlockSetterWithEmptyBlocksThrowsException() {
Map<BlockKey, Double> blocks = new HashMap<>();
assertThrows(

View file

@ -29,13 +29,13 @@ class MineTickerTest {
}
@Test
void testConstruction_WithValidParameters_DoesNotThrow() {
void testConstructionWithValidParametersDoesNotThrow() {
// Act & Assert
assertDoesNotThrow(() -> new MineTicker(mines, plugin));
}
@Test
void testStop_WhenNotRunning_DoesNotThrow() {
void testStopWhenNotRunningDoesNotThrow() {
// Arrange
MineTicker ticker = new MineTicker(mines, plugin);
@ -44,7 +44,7 @@ class MineTickerTest {
}
@Test
void testMultipleStops_DoNotThrow() {
void testMultipleStopsDoNotThrow() {
// Arrange
MineTicker ticker = new MineTicker(mines, plugin);

View file

@ -3,19 +3,12 @@ package dev.loki.lomines.core;
import dev.loki.lomines.LoMinesPlugin;
import dev.loki.lomines.core.mine.model.Mine;
import dev.loki.lomines.core.mine.registry.Mines;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.MockedStatic;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;
import java.io.IOException;
import java.nio.file.Files;
@ -23,19 +16,13 @@ import java.nio.file.Path;
import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@Disabled("WorldGuard dependency not available in unit tests")
class MinesLifecycleTest {
@TempDir
@ -43,43 +30,25 @@ class MinesLifecycleTest {
private Mines mines;
private LoMinesPlugin plugin;
private BukkitScheduler scheduler;
private MockedStatic<Bukkit> globalBukkit;
private ServerMock server;
@BeforeEach
void setUp() {
globalBukkit = mockStatic(Bukkit.class);
org.bukkit.plugin.PluginManager pluginManager = mock(org.bukkit.plugin.PluginManager.class);
Server server = mock(Server.class);
World world = mock(World.class);
BlockData blockData = mock(BlockData.class);
globalBukkit.when(Bukkit::getPluginManager).thenReturn(pluginManager);
globalBukkit.when(Bukkit::getServer).thenReturn(server);
globalBukkit.when(() -> Bukkit.getWorld(anyString())).thenReturn(world);
globalBukkit.when(() -> Bukkit.createBlockData(any(Material.class))).thenReturn(blockData);
when(world.getName()).thenReturn("world");
server = MockBukkit.mock();
server.addSimpleWorld("world");
plugin = mock(LoMinesPlugin.class);
Logger logger = mock(Logger.class);
scheduler = mock(BukkitScheduler.class);
when(plugin.getDataFolder()).thenReturn(tempDir.toFile());
when(plugin.getLogger()).thenReturn(logger);
globalBukkit.when(Bukkit::getScheduler).thenReturn(scheduler);
BukkitTask task = mock(BukkitTask.class);
when(scheduler.runTaskTimer(any(), any(Runnable.class), anyLong(), anyLong())).thenReturn(task);
mines = new Mines(plugin);
}
@AfterEach
void tearDown() {
if (globalBukkit != null) {
globalBukkit.close();
}
MockBukkit.unmock();
}
@Test
@ -97,9 +66,9 @@ class MinesLifecycleTest {
@Test
void testCreateMineCreatesFolder() throws IOException {
assertFalse(Files.exists(tempDir.resolve("mines")));
mines.create("testmine");
assertTrue(Files.isDirectory(tempDir.resolve("mines")));
mines.create("testmine");
assertTrue(Files.exists(tempDir.resolve("mines/testmine.yml")));
}
@Test

View file

@ -3,19 +3,12 @@ package dev.loki.lomines.core;
import dev.loki.lomines.LoMinesPlugin;
import dev.loki.lomines.core.mine.model.Mine;
import dev.loki.lomines.core.mine.registry.Mines;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.MockedStatic;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;
import java.io.IOException;
import java.nio.file.Files;
@ -25,15 +18,9 @@ import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@Disabled("WorldGuard dependency not available in unit tests")
class MinesLoadingTest {
private static final String FULL_YAML = """
@ -61,43 +48,25 @@ class MinesLoadingTest {
private Mines mines;
private LoMinesPlugin plugin;
private BukkitScheduler scheduler;
private MockedStatic<Bukkit> globalBukkit;
private ServerMock server;
@BeforeEach
void setUp() {
globalBukkit = mockStatic(Bukkit.class);
org.bukkit.plugin.PluginManager pluginManager = mock(org.bukkit.plugin.PluginManager.class);
Server server = mock(Server.class);
World world = mock(World.class);
BlockData blockData = mock(BlockData.class);
globalBukkit.when(Bukkit::getPluginManager).thenReturn(pluginManager);
globalBukkit.when(Bukkit::getServer).thenReturn(server);
globalBukkit.when(() -> Bukkit.getWorld(anyString())).thenReturn(world);
globalBukkit.when(() -> Bukkit.createBlockData(any(Material.class))).thenReturn(blockData);
when(world.getName()).thenReturn("world");
server = MockBukkit.mock();
server.addSimpleWorld("world");
plugin = mock(LoMinesPlugin.class);
Logger logger = mock(Logger.class);
scheduler = mock(BukkitScheduler.class);
when(plugin.getDataFolder()).thenReturn(tempDir.toFile());
when(plugin.getLogger()).thenReturn(logger);
globalBukkit.when(Bukkit::getScheduler).thenReturn(scheduler);
BukkitTask task = mock(BukkitTask.class);
when(scheduler.runTaskTimer(any(), any(Runnable.class), anyLong(), anyLong())).thenReturn(task);
mines = new Mines(plugin);
}
@AfterEach
void tearDown() {
if (globalBukkit != null) {
globalBukkit.close();
}
MockBukkit.unmock();
}
@Test

View file

@ -1,22 +1,13 @@
package dev.loki.lomines.core;
import dev.loki.lomines.LoMinesPlugin;
import dev.loki.lomines.core.mine.model.Mine;
import dev.loki.lomines.core.mine.registry.Mines;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.plugin.PluginManager;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.MockedStatic;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;
import java.io.IOException;
import java.nio.file.Files;
@ -25,19 +16,15 @@ import java.util.logging.Logger;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Unit tests for Mines registry.
*/
@Disabled("WorldGuard dependency not available in unit tests")
class MinesTest {
@TempDir
@ -45,43 +32,25 @@ class MinesTest {
private Mines mines;
private LoMinesPlugin plugin;
private BukkitScheduler scheduler;
private MockedStatic<Bukkit> globalBukkit;
private ServerMock server;
@BeforeEach
void setUp() {
globalBukkit = mockStatic(Bukkit.class);
PluginManager pluginManager = mock(PluginManager.class);
Server server = mock(Server.class);
World world = mock(World.class);
BlockData blockData = mock(BlockData.class);
globalBukkit.when(Bukkit::getPluginManager).thenReturn(pluginManager);
globalBukkit.when(Bukkit::getServer).thenReturn(server);
globalBukkit.when(() -> Bukkit.getWorld(anyString())).thenReturn(world);
globalBukkit.when(() -> Bukkit.createBlockData(any(Material.class))).thenReturn(blockData);
when(world.getName()).thenReturn("world");
server = MockBukkit.mock();
server.addSimpleWorld("world");
plugin = mock(LoMinesPlugin.class);
Logger logger = mock(Logger.class);
scheduler = mock(BukkitScheduler.class);
when(plugin.getDataFolder()).thenReturn(tempDir.toFile());
when(plugin.getLogger()).thenReturn(logger);
globalBukkit.when(Bukkit::getScheduler).thenReturn(scheduler);
BukkitTask task = mock(BukkitTask.class);
when(scheduler.runTaskTimer(any(), any(Runnable.class), anyLong(), anyLong())).thenReturn(task);
mines = new Mines(plugin);
}
@AfterEach
void tearDown() {
if (globalBukkit != null) {
globalBukkit.close();
}
MockBukkit.unmock();
}
@Test

View file

@ -30,7 +30,7 @@ class LeaderboardPositionTest {
}
@Test
void testGetPosition_ReturnsCorrectPosition() {
void testGetPositionReturnsCorrectPosition() {
UUID player1 = UUID.randomUUID();
UUID player2 = UUID.randomUUID();
UUID player3 = UUID.randomUUID();
@ -45,13 +45,13 @@ class LeaderboardPositionTest {
}
@Test
void testGetPosition_ReturnsMinusOneForNonExistentPlayer() {
void testGetPositionReturnsMinusOneForNonExistentPlayer() {
UUID playerId = UUID.randomUUID();
assertEquals(-1, leaderboard.getPosition(playerId), "Should return -1 for non-existent player");
}
@Test
void testGetPosition_ReturnsMinusOneForZeroBlocks() {
void testGetPositionReturnsMinusOneForZeroBlocks() {
UUID playerId = UUID.randomUUID();
statsManager.getOrCreate(playerId).setTotalBlocks(0);

View file

@ -32,7 +32,7 @@ class LeaderboardQueryTest {
}
@Test
void testGetTopByMine_SortedDescending() {
void testGetTopByMineSortedDescending() {
UUID player1 = UUID.randomUUID();
UUID player2 = UUID.randomUUID();
UUID player3 = UUID.randomUUID();
@ -49,7 +49,7 @@ class LeaderboardQueryTest {
}
@Test
void testGetTopByMine_FiltersZeroBlocks() {
void testGetTopByMineFiltersZeroBlocks() {
UUID player1 = UUID.randomUUID();
UUID player2 = UUID.randomUUID();
@ -62,7 +62,7 @@ class LeaderboardQueryTest {
}
@Test
void testGetTopByMine_OnlyIncludesSpecificMine() {
void testGetTopByMineOnlyIncludesSpecificMine() {
UUID player1 = UUID.randomUUID();
UUID player2 = UUID.randomUUID();

View file

@ -39,13 +39,13 @@ class LeaderboardTest {
}
@Test
void testGetTopTotal_EmptyStats() {
void testGetTopTotalEmptyStats() {
List<LeaderboardEntry> top = leaderboard.getTopTotal(10);
assertTrue(top.isEmpty(), "Top list should be empty when no stats exist");
}
@Test
void testGetTopTotal_SinglePlayer() {
void testGetTopTotalSinglePlayer() {
UUID playerId = UUID.randomUUID();
PlayerStats stats = statsManager.getOrCreate(playerId);
stats.setTotalBlocks(100);
@ -57,7 +57,7 @@ class LeaderboardTest {
}
@Test
void testGetTopTotal_SortedDescending() {
void testGetTopTotalSortedDescending() {
UUID player1 = UUID.randomUUID();
UUID player2 = UUID.randomUUID();
UUID player3 = UUID.randomUUID();
@ -74,7 +74,7 @@ class LeaderboardTest {
}
@Test
void testGetTopTotal_LimitRespected() {
void testGetTopTotalLimitRespected() {
for (int i = 0; i < 10; i++) {
UUID playerId = UUID.randomUUID();
statsManager.getOrCreate(playerId).setTotalBlocks(i + 1);
@ -85,7 +85,7 @@ class LeaderboardTest {
}
@Test
void testGetTopTotal_FiltersZeroBlocks() {
void testGetTopTotalFiltersZeroBlocks() {
UUID player1 = UUID.randomUUID();
UUID player2 = UUID.randomUUID();
@ -98,7 +98,7 @@ class LeaderboardTest {
}
@Test
void testGetTopTotal_CachingWorks() {
void testGetTopTotalCachingWorks() {
UUID playerId = UUID.randomUUID();
statsManager.getOrCreate(playerId).setTotalBlocks(100);
@ -113,7 +113,7 @@ class LeaderboardTest {
}
@Test
void testInvalidateCache_ClearsCache() {
void testInvalidateCacheClearsCache() {
UUID playerId = UUID.randomUUID();
statsManager.getOrCreate(playerId).setTotalBlocks(100);

View file

@ -1,7 +1,6 @@
package dev.loki.lomines.data;
import dev.loki.lomines.LoMinesPlugin;
import dev.loki.lomines.data.stats.model.PlayerStats;
import dev.loki.lomines.data.stats.service.StatsManager;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitScheduler;
@ -11,7 +10,6 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.MockedStatic;
import java.io.IOException;
import java.nio.file.Path;
import java.util.UUID;
import java.util.logging.Logger;

View file

@ -3,7 +3,6 @@ package dev.loki.lomines.data;
import dev.loki.lomines.LoMinesPlugin;
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;
import org.junit.jupiter.api.io.TempDir;

View file

@ -8,7 +8,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.MockedStatic;
import java.io.IOException;
import java.nio.file.Files;

View file

@ -10,14 +10,14 @@ import dev.loki.lomines.data.config.reset.ResetConfig;
import dev.loki.lomines.data.config.reward.RewardConfig;
import dev.loki.lomines.data.config.teleport.TeleportConfig;
import dev.loki.lomines.data.config.ui.UIConfig;
import dev.loki.lomines.util.location.geo.Cuboid;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;
import java.util.HashMap;
import java.util.List;
@ -25,112 +25,96 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Disabled("Paper API RegistryAccess not available in unit tests")
class MineConfigTest {
private ServerMock server;
private World world;
@BeforeEach
void setUp() {
server = MockBukkit.mock();
server.addSimpleWorld("world");
world = server.getWorld("world");
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
}
private RegionConfig testRegion() {
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 10, 74, 10);
return RegionConfig.fromSelections(List.of(loc1, loc2));
}
private BlockConfig testBlocks() {
Map<BlockKey, Double> weights = new HashMap<>();
weights.put(new BlockKey.Vanilla(Material.STONE), 100.0);
return new BlockConfig(weights, FillMode.CUBOID, null);
}
@Test
void testBuilder() {
try (MockedStatic<org.bukkit.Bukkit> bukkit = Mockito.mockStatic(org.bukkit.Bukkit.class)) {
World world = mock(World.class);
when(world.getName()).thenReturn("world");
bukkit.when(() -> org.bukkit.Bukkit.getWorld("world")).thenReturn(world);
RegionConfig region = testRegion();
BlockConfig blocks = testBlocks();
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 10, 74, 10);
RegionConfig region = RegionConfig.fromSelections(List.of(loc1, loc2));
MineConfig config = MineConfig.builder("testmine")
.region(region)
.blocks(blocks)
.reset(ResetConfig.defaults())
.rewards(RewardConfig.empty())
.teleport(TeleportConfig.disabled())
.ui(UIConfig.defaults())
.build();
Map<BlockKey, Double> weights = new HashMap<>();
weights.put(new BlockKey.Vanilla(Material.STONE), 100.0);
BlockConfig blocks = new BlockConfig(weights, FillMode.CUBOID, null);
MineConfig config = MineConfig.builder("testmine")
.region(region)
.blocks(blocks)
.reset(ResetConfig.defaults())
.rewards(RewardConfig.empty())
.teleport(TeleportConfig.disabled())
.ui(UIConfig.defaults())
.build();
assertEquals("testmine", config.name());
assertEquals(1, config.region().regionCount());
assertEquals(1, config.blocks().blockCount());
}
assertEquals("testmine", config.name());
assertEquals(1, config.region().regionCount());
assertEquals(1, config.blocks().blockCount());
}
@Test
void testDefaultsFactory() {
try (MockedStatic<org.bukkit.Bukkit> bukkit = Mockito.mockStatic(org.bukkit.Bukkit.class)) {
World world = mock(World.class);
when(world.getName()).thenReturn("world");
bukkit.when(() -> org.bukkit.Bukkit.getWorld("world")).thenReturn(world);
RegionConfig region = testRegion();
BlockConfig blocks = testBlocks();
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 10, 74, 10);
RegionConfig region = RegionConfig.fromSelections(List.of(loc1, loc2));
MineConfig config = MineConfigDefaults.defaults("mymine", region, blocks);
Map<BlockKey, Double> weights = new HashMap<>();
weights.put(new BlockKey.Vanilla(Material.STONE), 100.0);
BlockConfig blocks = new BlockConfig(weights, FillMode.CUBOID, null);
MineConfig config = MineConfigDefaults.defaults("mymine", region, blocks);
assertEquals("mymine", config.name());
assertNotNull(config.reset());
assertNotNull(config.rewards());
assertNotNull(config.teleport());
assertNotNull(config.ui());
}
assertEquals("mymine", config.name());
assertNotNull(config.reset());
assertNotNull(config.rewards());
assertNotNull(config.teleport());
assertNotNull(config.ui());
}
@Test
void testNameNormalized() {
try (MockedStatic<org.bukkit.Bukkit> bukkit = Mockito.mockStatic(org.bukkit.Bukkit.class)) {
World world = mock(World.class);
when(world.getName()).thenReturn("world");
bukkit.when(() -> org.bukkit.Bukkit.getWorld("world")).thenReturn(world);
RegionConfig region = testRegion();
BlockConfig blocks = testBlocks();
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 10, 74, 10);
RegionConfig region = RegionConfig.fromSelections(List.of(loc1, loc2));
MineConfig config = MineConfig.builder("TestMine_123 ")
.region(region)
.blocks(blocks)
.build();
Map<BlockKey, Double> weights = new HashMap<>();
weights.put(new BlockKey.Vanilla(Material.STONE), 100.0);
BlockConfig blocks = new BlockConfig(weights, FillMode.CUBOID, null);
MineConfig config = MineConfig.builder("TestMine_123 ")
.region(region)
.blocks(blocks)
.build();
assertEquals("testmine_123", config.name());
}
assertEquals("testmine_123", config.name());
}
@Test
void testWorldNameDelegation() {
try (MockedStatic<org.bukkit.Bukkit> bukkit = Mockito.mockStatic(org.bukkit.Bukkit.class)) {
World world = mock(World.class);
when(world.getName()).thenReturn("nether");
bukkit.when(() -> org.bukkit.Bukkit.getWorld("nether")).thenReturn(world);
server.addSimpleWorld("nether");
World nether = server.getWorld("nether");
Location loc1 = new Location(nether, 0, 64, 0);
Location loc2 = new Location(nether, 10, 74, 10);
RegionConfig region = RegionConfig.fromSelections(List.of(loc1, loc2));
BlockConfig blocks = testBlocks();
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 10, 74, 10);
RegionConfig region = RegionConfig.fromSelections(List.of(loc1, loc2));
MineConfig config = MineConfig.builder("test")
.region(region)
.blocks(blocks)
.build();
Map<BlockKey, Double> weights = new HashMap<>();
weights.put(new BlockKey.Vanilla(Material.STONE), 100.0);
BlockConfig blocks = new BlockConfig(weights, FillMode.CUBOID, null);
MineConfig config = MineConfig.builder("test")
.region(region)
.blocks(blocks)
.build();
assertEquals("nether", config.worldName());
}
assertEquals("nether", config.worldName());
}
}

View file

@ -8,21 +8,47 @@ import dev.loki.lomines.data.config.region.RegionConfig;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class MineConfigValidationTest {
private ServerMock server;
private World world;
@BeforeEach
void setUp() {
server = MockBukkit.mock();
server.addSimpleWorld("world");
world = server.getWorld("world");
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
}
private RegionConfig testRegion() {
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 10, 74, 10);
return RegionConfig.fromSelections(List.of(loc1, loc2));
}
private BlockConfig testBlocks() {
Map<BlockKey, Double> weights = new HashMap<>();
weights.put(new BlockKey.Vanilla(Material.STONE), 100.0);
return new BlockConfig(weights, FillMode.CUBOID, null);
}
@Test
void testNullNameThrows() {
assertThrows(NullPointerException.class, () ->
@ -30,35 +56,20 @@ class MineConfigValidationTest {
}
@Test
@Disabled("Paper API RegistryAccess not available in unit tests")
void testBlankNameThrows() {
try (MockedStatic<org.bukkit.Bukkit> bukkit = Mockito.mockStatic(org.bukkit.Bukkit.class)) {
World world = mock(World.class);
when(world.getName()).thenReturn("world");
bukkit.when(() -> org.bukkit.Bukkit.getWorld("world")).thenReturn(world);
RegionConfig region = testRegion();
BlockConfig blocks = testBlocks();
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 10, 74, 10);
RegionConfig region = RegionConfig.fromSelections(List.of(loc1, loc2));
Map<BlockKey, Double> weights = new HashMap<>();
weights.put(new BlockKey.Vanilla(Material.STONE), 100.0);
BlockConfig blocks = new BlockConfig(weights, FillMode.CUBOID, null);
assertThrows(IllegalArgumentException.class, () ->
MineConfig.builder(" ")
.region(region)
.blocks(blocks)
.build());
}
assertThrows(IllegalArgumentException.class, () ->
MineConfig.builder(" ")
.region(region)
.blocks(blocks)
.build());
}
@Test
@Disabled("Paper API RegistryAccess not available in unit tests")
void testNullRegionThrows() {
Map<BlockKey, Double> weights = new HashMap<>();
weights.put(new BlockKey.Vanilla(Material.STONE), 100.0);
BlockConfig blocks = new BlockConfig(weights, FillMode.CUBOID, null);
BlockConfig blocks = testBlocks();
assertThrows(NullPointerException.class, () ->
MineConfig.builder("test")
@ -69,20 +80,12 @@ class MineConfigValidationTest {
@Test
void testNullBlocksThrows() {
try (MockedStatic<org.bukkit.Bukkit> bukkit = Mockito.mockStatic(org.bukkit.Bukkit.class)) {
World world = mock(World.class);
when(world.getName()).thenReturn("world");
bukkit.when(() -> org.bukkit.Bukkit.getWorld("world")).thenReturn(world);
RegionConfig region = testRegion();
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 10, 74, 10);
RegionConfig region = RegionConfig.fromSelections(List.of(loc1, loc2));
assertThrows(NullPointerException.class, () ->
MineConfig.builder("test")
.region(region)
.blocks(null)
.build());
}
assertThrows(NullPointerException.class, () ->
MineConfig.builder("test")
.region(region)
.blocks(null)
.build());
}
}

View file

@ -1,8 +1,11 @@
package dev.loki.lomines.data.config.block;
import org.bukkit.Material;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;
import java.util.HashMap;
import java.util.Map;
@ -13,9 +16,20 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Disabled("Paper API RegistryAccess not available in unit tests")
class BlockConfigTest {
private ServerMock server;
@BeforeEach
void setUp() {
server = MockBukkit.mock();
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
}
@Test
void testValidConfig() {
Map<BlockKey, Double> weights = new HashMap<>();

View file

@ -1,17 +1,31 @@
package dev.loki.lomines.data.config.block;
import org.bukkit.Material;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockbukkit.mockbukkit.MockBukkit;
import org.mockbukkit.mockbukkit.ServerMock;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@Disabled("Paper API RegistryAccess not available in unit tests")
class BlockKeyTest {
private ServerMock server;
@BeforeEach
void setUp() {
server = MockBukkit.mock();
}
@AfterEach
void tearDown() {
MockBukkit.unmock();
}
@Test
void testVanillaSerialization() {
BlockKey.Vanilla stone = new BlockKey.Vanilla(Material.STONE);

View file

@ -6,7 +6,6 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class UIConfigTest {

View file

@ -16,7 +16,6 @@ import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -38,7 +37,7 @@ class ChunkUtilsRefreshTest {
}
@Test
void testUpdateChunks_withLargeRegion() {
void testUpdateChunksWithLargeRegion() {
Location loc1 = new Location(world, 0, 0, 0);
Location loc2 = new Location(world, 100, 100, 100);
when(world.getChunkAt(anyInt(), anyInt())).thenReturn(chunk);
@ -52,7 +51,7 @@ class ChunkUtilsRefreshTest {
}
@Test
void testUpdateChunks_withNoPlayers() {
void testUpdateChunksWithNoPlayers() {
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 5, 70, 5);
when(world.getChunkAt(anyInt(), anyInt())).thenReturn(chunk);

View file

@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -43,14 +42,14 @@ class ChunkUtilsTest {
}
@Test
void testUpdateChunks_withNullRegion_throwsException() {
void testUpdateChunksWithNullRegionThrowsException() {
assertThrows(IllegalArgumentException.class, () -> {
ChunkUtils.updateChunks(null);
});
}
@Test
void testUpdateChunks_withSingleChunkRegion() {
void testUpdateChunksWithSingleChunkRegion() {
// Create a small region within a single chunk
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 5, 70, 5);
@ -69,7 +68,7 @@ class ChunkUtilsTest {
}
@Test
void testUpdateChunks_withMultipleChunks() {
void testUpdateChunksWithMultipleChunks() {
// Create a region spanning multiple chunks (16 blocks per chunk)
Location loc1 = new Location(world, 0, 64, 0);
Location loc2 = new Location(world, 32, 70, 32);
@ -88,7 +87,7 @@ class ChunkUtilsTest {
}
@Test
void testUpdateChunks_withNegativeCoordinates() {
void testUpdateChunksWithNegativeCoordinates() {
// Test with negative coordinates
Location loc1 = new Location(world, -16, 64, -16);
Location loc2 = new Location(world, -1, 70, -1);

View file

@ -9,8 +9,6 @@ import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
class LocationParserErrorTest {

View file

@ -4,8 +4,6 @@ import dev.loki.lomines.util.format.TimeFormatter;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class TimeFormatterTest {

View file

@ -9,7 +9,6 @@ import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

View file

@ -26,7 +26,7 @@ class SelectionManagerTest {
}
@Test
void getSelection_createsNewSelectionIfNotExists() {
void getSelectionCreatesNewSelectionIfNotExists() {
Selection selection = manager.getSelection(playerId);
assertNotNull(selection);
@ -34,7 +34,7 @@ class SelectionManagerTest {
}
@Test
void getSelection_returnsSameInstanceOnMultipleCalls() {
void getSelectionReturnsSameInstanceOnMultipleCalls() {
Selection first = manager.getSelection(playerId);
Selection second = manager.getSelection(playerId);
@ -42,21 +42,21 @@ class SelectionManagerTest {
}
@Test
void getSelection_throwsExceptionForNullPlayerId() {
void getSelectionThrowsExceptionForNullPlayerId() {
assertThrows(IllegalArgumentException.class, () -> {
manager.getSelection(null);
});
}
@Test
void findSelection_returnsEmptyWhenNotExists() {
void findSelectionReturnsEmptyWhenNotExists() {
Optional<Selection> result = manager.findSelection(playerId);
assertTrue(result.isEmpty());
}
@Test
void findSelection_returnsSelectionWhenExists() {
void findSelectionReturnsSelectionWhenExists() {
Selection created = manager.getSelection(playerId);
Optional<Selection> found = manager.findSelection(playerId);
@ -65,33 +65,33 @@ class SelectionManagerTest {
}
@Test
void findSelection_throwsExceptionForNullPlayerId() {
void findSelectionThrowsExceptionForNullPlayerId() {
assertThrows(IllegalArgumentException.class, () -> {
manager.findSelection(null);
});
}
@Test
void hasSelection_returnsFalseWhenNotExists() {
void hasSelectionReturnsFalseWhenNotExists() {
assertFalse(manager.hasSelection(playerId));
}
@Test
void hasSelection_returnsTrueWhenExists() {
void hasSelectionReturnsTrueWhenExists() {
manager.getSelection(playerId);
assertTrue(manager.hasSelection(playerId));
}
@Test
void hasSelection_throwsExceptionForNullPlayerId() {
void hasSelectionThrowsExceptionForNullPlayerId() {
assertThrows(IllegalArgumentException.class, () -> {
manager.hasSelection(null);
});
}
@Test
void clearSelection_removesSelection() {
void clearSelectionRemovesSelection() {
manager.getSelection(playerId);
assertTrue(manager.hasSelection(playerId));
@ -101,14 +101,14 @@ class SelectionManagerTest {
}
@Test
void clearSelection_doesNothingWhenSelectionNotExists() {
void clearSelectionDoesNothingWhenSelectionNotExists() {
assertDoesNotThrow(() -> {
manager.clearSelection(playerId);
});
}
@Test
void clearSelection_throwsExceptionForNullPlayerId() {
void clearSelectionThrowsExceptionForNullPlayerId() {
assertThrows(IllegalArgumentException.class, () -> {
manager.clearSelection(null);
});

View file

@ -1,17 +1,14 @@
package dev.loki.lomines.util.selection;
import dev.loki.lomines.util.location.geo.Cuboid;
import org.bukkit.Location;
import org.bukkit.World;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;