refactor: drop lolib, add own scheduler, inventory GUI and void generator

This commit is contained in:
loki5512344 2026-10-06 13:41:25 +02:00
parent cc521dc284
commit 7e227e39a4
Signed by: boba
GPG key ID: 253067914055423B
47 changed files with 708 additions and 113 deletions

View file

@ -0,0 +1,72 @@
package dev.loki.loparkour.menu.gui.inventory;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class InventoryGuiTest {
private static final int ROWS = 2;
private static final int SLOTS_PER_ROW = 9;
private static final int SLOT_WITH_HANDLER = 5;
private static final int PLAIN_SLOT = 7;
private static final int OUT_OF_RANGE_SLOT = 40;
@Test
void testRowsBoundsAreEnforced() {
final InventoryGui gui = InventoryGui.create();
assertThrows(IllegalArgumentException.class, () -> gui.rows(0), "zero rows are rejected");
assertThrows(IllegalArgumentException.class, () -> gui.rows(7), "seven rows are rejected");
assertSame(gui, gui.rows(6), "rows() is fluent");
}
@Test
void testFillKeepsItemsPlacedBeforeIt() {
final InventoryGui gui = InventoryGui.create().rows(ROWS);
gui.setItem(SLOT_WITH_HANDLER, null, event -> {
});
gui.fill(null);
final Map<Integer, InventoryGui.PlacedItem> items = gui.items();
assertEquals(ROWS * SLOTS_PER_ROW, items.size(), "fill covers every slot exactly once");
assertNotNull(items.get(SLOT_WITH_HANDLER).onClick(), "fill must not overwrite placed items");
assertNull(items.get(PLAIN_SLOT).onClick(), "a plain filler slot has no handler");
}
@Test
void testClickRunsHandlerAndCancelsTheEvent() {
final AtomicBoolean clicked = new AtomicBoolean();
final InventoryGui gui = InventoryGui.create().rows(ROWS);
gui.setItem(SLOT_WITH_HANDLER, null, event -> clicked.set(true));
final InventoryClickEvent event = Mockito.mock(InventoryClickEvent.class);
when(event.getRawSlot()).thenReturn(SLOT_WITH_HANDLER);
gui.handleClick(event);
verify(event).setCancelled(true);
assertTrue(clicked.get(), "the registered handler must run");
}
@Test
void testClickOnUnknownSlotOnlyCancels() {
final InventoryGui gui = InventoryGui.create().rows(ROWS);
final InventoryClickEvent event = Mockito.mock(InventoryClickEvent.class);
when(event.getRawSlot()).thenReturn(OUT_OF_RANGE_SLOT);
gui.handleClick(event);
verify(event).setCancelled(true);
}
}

View file

@ -0,0 +1,22 @@
package dev.loki.loparkour.scheduler;
import org.bukkit.plugin.Plugin;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
class SchedulerTest {
@Test
void testNoFoliaOnPlainJvm() {
assertFalse(Scheduler.isFolia(), "Folia server classes are absent in the test JVM");
}
@Test
void testInstancesAreCachedPerPlugin() {
final Plugin plugin = Mockito.mock(Plugin.class);
assertSame(Scheduler.get(plugin), Scheduler.get(plugin), "the same plugin must reuse one scheduler");
}
}

View file

@ -0,0 +1,25 @@
package dev.loki.loparkour.world.core;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
class VoidGeneratorTest {
@Test
void testGeneratorIsShared() {
assertSame(VoidGenerator.getGenerator(), VoidGenerator.getGenerator(), "the generator is a singleton");
}
@Test
void testGeneratesNothing() {
final VoidGenerator generator = VoidGenerator.getGenerator();
assertFalse(generator.shouldGenerateNoise(), "noise off");
assertFalse(generator.shouldGenerateSurface(), "surface off");
assertFalse(generator.shouldGenerateCaves(), "caves off");
assertFalse(generator.shouldGenerateDecorations(), "decorations off");
assertFalse(generator.shouldGenerateMobs(), "mobs off");
assertFalse(generator.shouldGenerateStructures(), "structures off");
}
}