diff --git a/pom.xml b/pom.xml index 3edab1a..8d7473b 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ -LOCAL - 2.25.0 + 2.26.0 BentoBoxWorld_Level bentobox-world https://sonarcloud.io diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index 4af0b59..da58a37 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -102,6 +102,7 @@ public void onLoad() { this.saveResource("panels/top_panel.yml", false); this.saveResource("panels/detail_panel.yml", false); this.saveResource("panels/value_panel.yml", false); + this.saveResource("panels/donation_panel.yml", false); } private boolean loadSettings() { diff --git a/src/main/java/world/bentobox/level/panels/DonationPanel.java b/src/main/java/world/bentobox/level/panels/DonationPanel.java index 4dbf373..ccb5ae7 100644 --- a/src/main/java/world/bentobox/level/panels/DonationPanel.java +++ b/src/main/java/world/bentobox/level/panels/DonationPanel.java @@ -1,9 +1,12 @@ package world.bentobox.level.panels; +import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -23,6 +26,8 @@ import net.kyori.adventure.text.format.TextDecoration; import world.bentobox.bentobox.api.localization.TextVariables; +import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord; +import world.bentobox.bentobox.api.panels.reader.TemplateReader; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.util.Util; @@ -37,30 +42,15 @@ */ public class DonationPanel implements Listener { - private static final int SIZE = 36; // 4 rows - private static final String TITLE_REF = "island.donate.gui-title"; private static final String POINTS_PLACEHOLDER = "[points]"; - // Slot layout - private static final int INFO_SLOT = 4; - private static final int CANCEL_SLOT = 28; - private static final int PREVIEW_SLOT = 31; - private static final int CONFIRM_SLOT = 34; - - // Donation slots: rows 2 and 3, columns 2-8 (slots 10-16, 19-25) - private static final int[] DONATION_SLOTS = { - 10, 11, 12, 13, 14, 15, 16, - 19, 20, 21, 22, 23, 24, 25 - }; - - // Border slots: everything else - private static final Material BORDER_MATERIAL = Material.BLACK_STAINED_GLASS_PANE; - private final Level addon; private final World world; private final User user; private final Island island; private final Inventory inventory; + private final DonationPanelLayout layout; + private final Set donationSlotSet; private boolean confirmed = false; private DonationPanel(Level addon, World world, User user, Island island) { @@ -68,47 +58,73 @@ private DonationPanel(Level addon, World world, User user, Island island) { this.world = world; this.user = user; this.island = island; + this.layout = loadLayout(addon); + this.donationSlotSet = HashSet.newHashSet(layout.donationSlots.length); + for (int s : layout.donationSlots) { + donationSlotSet.add(s); + } - // Create the inventory + // Create the inventory — use the title from the template (falls back to the + // default translation key when no template title is set). Component title = removeDefaultItalic( - Util.parseMiniMessageOrLegacy(user.getTranslation(TITLE_REF))); - this.inventory = Bukkit.createInventory(null, SIZE, title); - - // Fill borders - ItemStack border = createNamedItem(BORDER_MATERIAL, " "); - for (int i = 0; i < SIZE; i++) { - inventory.setItem(i, border); + Util.parseMiniMessageOrLegacy(user.getTranslation(layout.panelTitle))); + this.inventory = Bukkit.createInventory(null, layout.size, title); + + // Fill borders if a border material is configured + if (layout.borderMaterial != null && layout.borderMaterial != Material.AIR) { + ItemStack border = createNamedItem(layout.borderMaterial, " "); + for (int i = 0; i < layout.size; i++) { + if (!donationSlotSet.contains(i) + && i != layout.infoSlot && i != layout.cancelSlot + && i != layout.previewSlot && i != layout.confirmSlot + && !layout.decorativeItems.containsKey(i)) { + inventory.setItem(i, border); + } + } } - // Clear donation slots - for (int slot : DONATION_SLOTS) { - inventory.setItem(slot, null); - } + // Place decorative items from the template (non-button, non-border entries) + layout.decorativeItems.forEach(inventory::setItem); // Info pane long currentDonated = addon.getManager().getDonatedPoints(island); - ItemStack info = createNamedItem(Material.BOOK, + ItemStack info = createNamedItem(layout.infoMaterial, user.getTranslation("island.donate.gui-info", POINTS_PLACEHOLDER, Utils.formatNumber(user, currentDonated))); - inventory.setItem(INFO_SLOT, info); + inventory.setItem(layout.infoSlot, info); // Cancel button - ItemStack cancel = createNamedItem(Material.RED_STAINED_GLASS_PANE, - user.getTranslation("island.donate.cancel")); - inventory.setItem(CANCEL_SLOT, cancel); + String cancelKey = layout.cancelTitleOverride != null + ? layout.cancelTitleOverride : "island.donate.cancel"; + ItemStack cancel = createNamedItem(layout.cancelMaterial, + user.getTranslation(cancelKey)); + inventory.setItem(layout.cancelSlot, cancel); // Preview pane (starts at 0) updatePreview(); // Confirm button - ItemStack confirm = createNamedItem(Material.LIME_STAINED_GLASS_PANE, - user.getTranslation("island.donate.confirm")); - inventory.setItem(CONFIRM_SLOT, confirm); + String confirmKey = layout.confirmTitleOverride != null + ? layout.confirmTitleOverride : "island.donate.confirm"; + ItemStack confirm = createNamedItem(layout.confirmMaterial, + user.getTranslation(confirmKey)); + inventory.setItem(layout.confirmSlot, confirm); // Register listener Bukkit.getPluginManager().registerEvents(this, addon.getPlugin()); } + private static DonationPanelLayout loadLayout(Level addon) { + try { + File panelFolder = new File(addon.getDataFolder(), "panels"); + PanelTemplateRecord template = TemplateReader.readTemplatePanel("donation_panel", panelFolder); + return DonationPanelLayout.fromTemplate(template); + } catch (Exception e) { + addon.logError("Could not load donation_panel template, using default layout."); + return DonationPanelLayout.defaults(); + } + } + private void build() { user.getPlayer().openInventory(inventory); } @@ -118,7 +134,7 @@ private void build() { */ private long calculateDonationValue() { long total = 0; - for (int slot : DONATION_SLOTS) { + for (int slot : layout.donationSlots) { ItemStack item = inventory.getItem(slot); if (item != null && !item.getType().isAir()) { Integer value = addon.getBlockConfig().getValue(world, item.getType()); @@ -135,20 +151,17 @@ private long calculateDonationValue() { */ private void updatePreview() { long points = calculateDonationValue(); - ItemStack preview = createNamedItem(Material.EXPERIENCE_BOTTLE, + ItemStack preview = createNamedItem(layout.previewMaterial, user.getTranslation("island.donate.preview", POINTS_PLACEHOLDER, Utils.formatNumber(user, points))); - inventory.setItem(PREVIEW_SLOT, preview); + inventory.setItem(layout.previewSlot, preview); } /** * Check if a slot is a donation slot. */ private boolean isDonationSlot(int slot) { - for (int s : DONATION_SLOTS) { - if (s == slot) return true; - } - return false; + return donationSlotSet.contains(slot); } /** @@ -160,7 +173,7 @@ private void processDonation() { long totalPoints = 0; Player player = user.getPlayer(); - for (int slot : DONATION_SLOTS) { + for (int slot : layout.donationSlots) { ItemStack item = inventory.getItem(slot); if (item != null && !item.getType().isAir()) { Material mat = item.getType(); @@ -199,7 +212,7 @@ private void processDonation() { */ private void returnItems() { Player player = user.getPlayer(); - for (int slot : DONATION_SLOTS) { + for (int slot : layout.donationSlots) { ItemStack item = inventory.getItem(slot); if (item != null && !item.getType().isAir()) { Map overflow = player.getInventory().addItem(item); @@ -224,15 +237,15 @@ public void onInventoryClick(InventoryClickEvent event) { int slot = event.getRawSlot(); - if (slot >= SIZE) { + if (slot >= layout.size) { handlePlayerInventoryClick(event); return; } - if (slot == CANCEL_SLOT) { + if (slot == layout.cancelSlot) { handleCancel(event, player); return; } - if (slot == CONFIRM_SLOT) { + if (slot == layout.confirmSlot) { handleConfirm(event, player); return; } @@ -268,8 +281,8 @@ private void handlePlayerInventoryClick(InventoryClickEvent event) { */ private ItemStack distributeIntoDonationSlots(ItemStack remaining) { int idx = 0; - while (idx < DONATION_SLOTS.length && remaining.getAmount() > 0) { - int ds = DONATION_SLOTS[idx]; + while (idx < layout.donationSlots.length && remaining.getAmount() > 0) { + int ds = layout.donationSlots[idx]; ItemStack existing = inventory.getItem(ds); if (existing == null || existing.getType().isAir()) { inventory.setItem(ds, remaining.clone()); @@ -336,7 +349,7 @@ public void onInventoryDrag(InventoryDragEvent event) { if (!event.getInventory().equals(inventory)) return; // Only allow drags into donation slots for (int slot : event.getRawSlots()) { - if (slot < SIZE && !isDonationSlot(slot)) { + if (slot < layout.size && !isDonationSlot(slot)) { event.setCancelled(true); return; } diff --git a/src/main/java/world/bentobox/level/panels/DonationPanelLayout.java b/src/main/java/world/bentobox/level/panels/DonationPanelLayout.java new file mode 100644 index 0000000..6ea336d --- /dev/null +++ b/src/main/java/world/bentobox/level/panels/DonationPanelLayout.java @@ -0,0 +1,248 @@ +package world.bentobox.level.panels; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord; +import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord; + +/** + * Resolved slot layout for the donation panel. Built from a + * {@link PanelTemplateRecord} (loaded from {@code panels/donation_panel.yml}), + * with a hardcoded fallback used when the template is missing or malformed. + */ +final class DonationPanelLayout { + + static final int DEFAULT_SIZE = 36; + static final int DEFAULT_INFO_SLOT = 4; + static final int DEFAULT_CANCEL_SLOT = 28; + static final int DEFAULT_PREVIEW_SLOT = 31; + static final int DEFAULT_CONFIRM_SLOT = 34; + static final Material DEFAULT_BORDER_MATERIAL = Material.BLACK_STAINED_GLASS_PANE; + static final String DEFAULT_TITLE_REF = "island.donate.gui-title"; + static final int[] DEFAULT_DONATION_SLOTS = { + 10, 11, 12, 13, 14, 15, 16, + 19, 20, 21, 22, 23, 24, 25 + }; + + private static final String DATA_TYPE = "type"; + private static final String TYPE_INFO = "INFO"; + private static final String TYPE_CANCEL = "CANCEL"; + private static final String TYPE_PREVIEW = "PREVIEW"; + private static final String TYPE_CONFIRM = "CONFIRM"; + + final int size; + final int infoSlot; + final int cancelSlot; + final int previewSlot; + final int confirmSlot; + final int[] donationSlots; + final Material borderMaterial; + final Material infoMaterial; + final Material cancelMaterial; + final Material previewMaterial; + final Material confirmMaterial; + final String cancelTitleOverride; + final String confirmTitleOverride; + /** Translation key (or literal text) for the inventory title. */ + final String panelTitle; + /** + * Decorative items keyed by absolute slot index. These are template entries + * whose {@code data.type} is absent or unrecognised. They reserve their slot + * (keeping donated blocks out) and should be placed visibly in the inventory. + */ + final Map decorativeItems; + + private DonationPanelLayout(Builder b) { + this.size = b.size; + this.infoSlot = b.infoSlot; + this.cancelSlot = b.cancelSlot; + this.previewSlot = b.previewSlot; + this.confirmSlot = b.confirmSlot; + this.donationSlots = b.donationSlots; + this.borderMaterial = b.borderMaterial; + this.infoMaterial = b.infoMaterial; + this.cancelMaterial = b.cancelMaterial; + this.previewMaterial = b.previewMaterial; + this.confirmMaterial = b.confirmMaterial; + this.cancelTitleOverride = b.cancelTitleOverride; + this.confirmTitleOverride = b.confirmTitleOverride; + this.panelTitle = b.panelTitle; + this.decorativeItems = Collections.unmodifiableMap(b.decorativeItems); + } + + /** + * The hardcoded 4-row layout used before the template was added, and as a + * fallback when the template cannot be parsed. + */ + static DonationPanelLayout defaults() { + Builder b = new Builder(); + b.size = DEFAULT_SIZE; + b.infoSlot = DEFAULT_INFO_SLOT; + b.cancelSlot = DEFAULT_CANCEL_SLOT; + b.previewSlot = DEFAULT_PREVIEW_SLOT; + b.confirmSlot = DEFAULT_CONFIRM_SLOT; + b.donationSlots = DEFAULT_DONATION_SLOTS.clone(); + b.borderMaterial = DEFAULT_BORDER_MATERIAL; + return new DonationPanelLayout(b); + } + + /** + * Resolve a layout from a panel template. Returns {@link #defaults()} if the + * template is null or doesn't define all four named buttons (INFO, CANCEL, + * PREVIEW, CONFIRM) — partial layouts would be unusable. + */ + static DonationPanelLayout fromTemplate(PanelTemplateRecord template) { + if (template == null) { + return defaults(); + } + int rowCount = computeRowCount(template); + if (rowCount < 1) { + return defaults(); + } + + Builder b = new Builder(); + ItemTemplateRecord[][] content = template.content(); + for (int r = 0; r < rowCount; r++) { + for (int c = 0; c < 9; c++) { + processCell(b, r * 9 + c, content[r][c]); + } + } + + if (b.infoSlot < 0 || b.cancelSlot < 0 || b.previewSlot < 0 || b.confirmSlot < 0) { + // A required button is missing - fall back rather than render a broken UI. + return defaults(); + } + + Material borderMat = materialOf(template.border() == null ? null : template.border().icon()); + boolean hasBorder = borderMat != null && borderMat != Material.AIR; + b.borderMaterial = hasBorder ? borderMat : Material.AIR; + b.size = rowCount * 9; + b.donationSlots = computeDonationSlots(rowCount, b.occupied, hasBorder); + b.panelTitle = (template.title() != null && !template.title().isBlank()) + ? template.title() + : DEFAULT_TITLE_REF; + return new DonationPanelLayout(b); + } + + /** + * Apply a single template cell to the builder: reserve its slot, then either + * record it as a named button, decorative item, or unrecognised entry. + */ + private static void processCell(Builder b, int slot, ItemTemplateRecord rec) { + if (rec == null) { + return; + } + // Any non-null template entry reserves the slot, even if its data.type is + // unknown - admins shouldn't see decorative items overwritten by donated blocks. + b.occupied.add(slot); + Object typeObj = rec.dataMap().get(DATA_TYPE); + if (typeObj == null) { + addDecorative(b, slot, rec); + return; + } + switch (String.valueOf(typeObj)) { + case TYPE_INFO -> { + b.infoSlot = slot; + Material m = materialOf(rec.icon()); + if (m != null) b.infoMaterial = m; + } + case TYPE_CANCEL -> { + b.cancelSlot = slot; + Material m = materialOf(rec.icon()); + if (m != null) b.cancelMaterial = m; + b.cancelTitleOverride = rec.title(); + } + case TYPE_PREVIEW -> { + b.previewSlot = slot; + Material m = materialOf(rec.icon()); + if (m != null) b.previewMaterial = m; + } + case TYPE_CONFIRM -> { + b.confirmSlot = slot; + Material m = materialOf(rec.icon()); + if (m != null) b.confirmMaterial = m; + b.confirmTitleOverride = rec.title(); + } + default -> addDecorative(b, slot, rec); + } + } + + private static void addDecorative(Builder b, int slot, ItemTemplateRecord rec) { + ItemStack icon = rec.icon(); + if (icon != null) { + b.decorativeItems.put(slot, icon.clone()); + } + } + + private static int computeRowCount(PanelTemplateRecord template) { + int max = 0; + boolean[] forced = template.forcedRows(); + if (forced != null) { + for (int i = 0; i < forced.length; i++) { + if (forced[i]) max = Math.max(max, i + 1); + } + } + ItemTemplateRecord[][] content = template.content(); + for (int r = 0; r < content.length; r++) { + for (int c = 0; c < content[r].length; c++) { + if (content[r][c] != null) { + max = Math.max(max, r + 1); + break; + } + } + } + return Math.min(max, 6); + } + + private static int[] computeDonationSlots(int rowCount, Set reserved, boolean hasBorder) { + int[] tmp = new int[rowCount * 9]; + int n = 0; + for (int r = 0; r < rowCount; r++) { + for (int c = 0; c < 9; c++) { + int slot = r * 9 + c; + boolean borderEdge = hasBorder + && (r == 0 || r == rowCount - 1 || c == 0 || c == 8); + if (!reserved.contains(slot) && !borderEdge) { + tmp[n++] = slot; + } + } + } + return Arrays.copyOf(tmp, n); + } + + private static Material materialOf(ItemStack icon) { + return icon == null ? null : icon.getType(); + } + + /** + * Mutable accumulator used while resolving a template into a layout. Keeps + * the resolution code free of long parameter lists and cross-method state + * juggling. + */ + private static final class Builder { + int size = DEFAULT_SIZE; + int infoSlot = -1; + int cancelSlot = -1; + int previewSlot = -1; + int confirmSlot = -1; + int[] donationSlots = DEFAULT_DONATION_SLOTS.clone(); + Material borderMaterial = DEFAULT_BORDER_MATERIAL; + Material infoMaterial = Material.BOOK; + Material cancelMaterial = Material.RED_STAINED_GLASS_PANE; + Material previewMaterial = Material.EXPERIENCE_BOTTLE; + Material confirmMaterial = Material.LIME_STAINED_GLASS_PANE; + String cancelTitleOverride; + String confirmTitleOverride; + String panelTitle = DEFAULT_TITLE_REF; + final Set occupied = new LinkedHashSet<>(); + final Map decorativeItems = new LinkedHashMap<>(); + } +} diff --git a/src/main/resources/panels/donation_panel.yml b/src/main/resources/panels/donation_panel.yml new file mode 100644 index 0000000..9d425ba --- /dev/null +++ b/src/main/resources/panels/donation_panel.yml @@ -0,0 +1,35 @@ +donation_panel: + title: island.donate.gui-title + type: INVENTORY + border: + icon: BLACK_STAINED_GLASS_PANE + title: " " + # Row numbers that must always be shown (1-6). List all rows you want visible. + # The donation grid is every cell that is neither a border slot nor one of the + # four named buttons below. + force-shown: [1,2,3,4] + content: + 1: + 5: + icon: BOOK + data: + # INFO pane: shows total points already donated. + type: INFO + 4: + 2: + icon: RED_STAINED_GLASS_PANE + title: island.donate.cancel + data: + # CANCEL button: returns items and closes the panel. + type: CANCEL + 5: + icon: EXPERIENCE_BOTTLE + data: + # PREVIEW pane: shows pending point value of items in the grid. + type: PREVIEW + 8: + icon: LIME_STAINED_GLASS_PANE + title: island.donate.confirm + data: + # CONFIRM button: destroys items and credits points. + type: CONFIRM diff --git a/src/test/java/world/bentobox/level/CommonTestSetup.java b/src/test/java/world/bentobox/level/CommonTestSetup.java index 876424a..2ec1835 100644 --- a/src/test/java/world/bentobox/level/CommonTestSetup.java +++ b/src/test/java/world/bentobox/level/CommonTestSetup.java @@ -137,7 +137,7 @@ public abstract class CommonTestSetup { @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { MockitoAnnotations.openMocks(this); // Processes the @Mock annotations and initializes the field closeable = MockitoAnnotations.openMocks(this); @@ -266,7 +266,7 @@ public void setUp() throws Exception { * @throws Exception */ @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { // IMPORTANT: Explicitly close the mock to prevent leakage mockedBukkit.closeOnDemand(); mockedUtil.closeOnDemand(); diff --git a/src/test/java/world/bentobox/level/LevelTest.java b/src/test/java/world/bentobox/level/LevelTest.java index c436e27..288fec9 100644 --- a/src/test/java/world/bentobox/level/LevelTest.java +++ b/src/test/java/world/bentobox/level/LevelTest.java @@ -58,7 +58,7 @@ * @author tastybento * */ -public class LevelTest extends CommonTestSetup { +class LevelTest extends CommonTestSetup { private static File jFile; @Mock @@ -91,7 +91,7 @@ public class LevelTest extends CommonTestSetup { private MockedStatic itemsAdderMock; @BeforeAll - public static void beforeClass() throws IOException { + protected static void beforeClass() throws IOException { // Make the addon jar jFile = new File("addon.jar"); // Copy over config file from src folder @@ -121,7 +121,7 @@ public static void beforeClass() throws IOException { */ @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(plugin.getHooks()).thenReturn(hm); @@ -198,13 +198,13 @@ public void setUp() throws Exception { */ @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); deleteAll(new File("database")); } @AfterAll - public static void cleanUp() throws Exception { + protected static void cleanUp() throws Exception { new File("addon.jar").delete(); new File("config.yml").delete(); new File("blockconfig.yml").delete(); @@ -215,7 +215,7 @@ public static void cleanUp() throws Exception { * Test method for {@link world.bentobox.level.Level#allLoaded() */ @Test - public void testAllLoaded() { + void testAllLoaded() { mockedBukkit.when(() -> Bukkit.getWorld("acidisland_world")).thenReturn(null); addon.allLoaded(); verify(plugin).log("[Level] Level hooking into BSkyBlock"); @@ -241,7 +241,7 @@ public void testAllLoaded() { * Test method for {@link world.bentobox.level.Level#getSettings()}. */ @Test - public void testGetSettings() { + void testGetSettings() { addon.onEnable(); ConfigSettings s = addon.getSettings(); assertEquals(100, s.getLevelCost()); diff --git a/src/test/java/world/bentobox/level/LevelsManagerTest.java b/src/test/java/world/bentobox/level/LevelsManagerTest.java index c88886c..91d841d 100644 --- a/src/test/java/world/bentobox/level/LevelsManagerTest.java +++ b/src/test/java/world/bentobox/level/LevelsManagerTest.java @@ -1,8 +1,8 @@ package world.bentobox.level; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +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.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; @@ -23,9 +23,9 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.junit.Test; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockedStatic; @@ -40,7 +40,6 @@ import world.bentobox.bentobox.database.DatabaseSetup; import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType; import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.level.calculators.Pipeliner; import world.bentobox.level.calculators.Results; @@ -52,7 +51,7 @@ * @author tastybento * */ -public class LevelsManagerTest extends CommonTestSetup { +class LevelsManagerTest extends CommonTestSetup { @Mock private AbstractDatabaseHandler handler; @@ -75,8 +74,6 @@ public class LevelsManagerTest extends CommonTestSetup { @Mock private Inventory inv; @Mock - private IslandWorldManager iwm; - @Mock private IslandLevels levelsData; //@Mock //private BukkitScheduler scheduler; @@ -87,7 +84,7 @@ public class LevelsManagerTest extends CommonTestSetup { @SuppressWarnings("unchecked") @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); handler = mock(AbstractDatabaseHandler.class); @@ -176,8 +173,10 @@ public void setUp() throws Exception { // Inventory GUI mockedBukkit.when(() -> Bukkit.createInventory(any(), anyInt(), anyString())).thenReturn(inv); + // No online players — hasTopTenPerm short-circuits to true via the null check. + mockedBukkit.when(() -> Bukkit.getPlayer(any(UUID.class))).thenReturn(null); + // IWM - // when(plugin.getIWM()).thenReturn(iwm); when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock."); lm = new LevelsManager(addon); @@ -189,7 +188,7 @@ public void setUp() throws Exception { */ @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); deleteAll(new File("database")); User.clearUsers(); @@ -201,7 +200,7 @@ public void tearDown() throws Exception { * {@link world.bentobox.level.LevelsManager#calculateLevel(UUID, world.bentobox.bentobox.database.objects.Island)}. */ @Test - public void testCalculateLevel() { + void testCalculateLevel() { Results results = new Results(); results.setLevel(10000); results.setInitialCount(300L); @@ -227,7 +226,7 @@ public void testCalculateLevel() { * {@link world.bentobox.level.LevelsManager#getInitialCount(world.bentobox.bentobox.database.objects.Island)}. */ @Test - public void testGetInitialCount() { + void testGetInitialCount() { assertEquals(2614500L, lm.getInitialCount(island)); } @@ -236,7 +235,7 @@ public void testGetInitialCount() { * {@link world.bentobox.level.LevelsManager#getIslandLevel(org.bukkit.World, java.util.UUID)}. */ @Test - public void testGetIslandLevel() { + void testGetIslandLevel() { assertEquals(-5, lm.getIslandLevel(world, uuid)); } @@ -245,7 +244,7 @@ public void testGetIslandLevel() { * {@link world.bentobox.level.LevelsManager#getPointsToNextString(org.bukkit.World, java.util.UUID)}. */ @Test - public void testGetPointsToNextString() { + void testGetPointsToNextString() { // No island player assertEquals("", lm.getPointsToNextString(world, UUID.randomUUID())); // Player has island @@ -257,7 +256,7 @@ public void testGetPointsToNextString() { * {@link world.bentobox.level.LevelsManager#getIslandLevelString(org.bukkit.World, java.util.UUID)}. */ @Test - public void testGetIslandLevelString() { + void testGetIslandLevelString() { assertEquals("-5", lm.getIslandLevelString(world, uuid)); } @@ -266,7 +265,7 @@ public void testGetIslandLevelString() { * {@link world.bentobox.level.LevelsManager#getLevelsData(java.util.UUID)}. */ @Test - public void testGetLevelsData() { + void testGetLevelsData() { assertEquals(levelsData, lm.getLevelsData(island)); } @@ -275,7 +274,7 @@ public void testGetLevelsData() { * Test method for {@link world.bentobox.level.LevelsManager#formatLevel(long)}. */ @Test - public void testFormatLevel() { + void testFormatLevel() { assertEquals("123456789", lm.formatLevel(123456789L)); settings.setShorthand(true); assertEquals("123.5M", lm.formatLevel(123456789L)); @@ -291,7 +290,7 @@ public void testFormatLevel() { * {@link world.bentobox.level.LevelsManager#getTopTen(org.bukkit.World, int)}. */ @Test - public void testGetTopTenEmpty() { + void testGetTopTenEmpty() { Map tt = lm.getTopTen(world, Level.TEN); assertTrue(tt.isEmpty()); } @@ -301,7 +300,7 @@ public void testGetTopTenEmpty() { * {@link world.bentobox.level.LevelsManager#getTopTen(org.bukkit.World, int)}. */ @Test - public void testGetTopTen() { + void testGetTopTen() { testLoadTopTens(); Map tt = lm.getTopTen(world, Level.TEN); assertFalse(tt.isEmpty()); @@ -314,7 +313,7 @@ public void testGetTopTen() { * {@link world.bentobox.level.LevelsManager#getWeightedTopTen(org.bukkit.World, int)}. */ @Test - public void testGetWeightedTopTen() { + void testGetWeightedTopTen() { testLoadTopTens(); Map tt = lm.getWeightedTopTen(world, Level.TEN); assertFalse(tt.isEmpty()); @@ -327,7 +326,7 @@ public void testGetWeightedTopTen() { * {@link world.bentobox.level.LevelsManager#hasTopTenPerm(org.bukkit.World, java.util.UUID)}. */ @Test - public void testHasTopTenPerm() { + void testHasTopTenPerm() { assertTrue(lm.hasTopTenPerm(world, uuid)); } @@ -335,7 +334,7 @@ public void testHasTopTenPerm() { * Test method for {@link world.bentobox.level.LevelsManager#loadTopTens()}. */ @Test - public void testLoadTopTens() { + void testLoadTopTens() { ArgumentCaptor task = ArgumentCaptor.forClass(Runnable.class); lm.loadTopTens(); mockedBukkit.verify(() -> Bukkit.getScheduler()); @@ -351,7 +350,7 @@ public void testLoadTopTens() { * {@link world.bentobox.level.LevelsManager#removeEntry(org.bukkit.World, java.util.UUID)}. */ @Test - public void testRemoveEntry() { + void testRemoveEntry() { testLoadTopTens(); Map tt = lm.getTopTen(world, Level.TEN); assertTrue(tt.containsKey(uuid.toString())); @@ -365,7 +364,7 @@ public void testRemoveEntry() { * {@link world.bentobox.level.LevelsManager#setInitialIslandLevel(world.bentobox.bentobox.database.objects.Island, long)}. */ @Test - public void testSetInitialIslandLevel() { + void testSetInitialIslandLevel() { lm.setInitialIslandCount(island, Level.TEN); assertEquals(Level.TEN, lm.getInitialCount(island)); } @@ -375,7 +374,7 @@ public void testSetInitialIslandLevel() { * {@link world.bentobox.level.LevelsManager#setIslandLevel(org.bukkit.World, java.util.UUID, long)}. */ @Test - public void testSetIslandLevel() { + void testSetIslandLevel() { lm.setIslandLevel(world, uuid, 1234); assertEquals(1234, lm.getIslandLevel(world, uuid)); @@ -387,7 +386,7 @@ public void testSetIslandLevel() { * Verifies that the top ten is sorted in descending order by level. */ @Test - public void testGetTopTenSortOrder() { + void testGetTopTenSortOrder() { lm.createAndCleanRankings(world); Map ttl = lm.getTopTenLists(); Map tt = ttl.get(world).getTopTen(); @@ -410,8 +409,8 @@ public void testGetTopTenSortOrder() { // Verify descending order long previousLevel = Long.MAX_VALUE; for (Long level : topTen.values()) { - assertTrue("Top ten not in descending order: " + level + " should be <= " + previousLevel, - level <= previousLevel); + assertTrue(level <= previousLevel, + "Top ten not in descending order: " + level + " should be <= " + previousLevel); previousLevel = level; } // Verify highest is first @@ -423,7 +422,7 @@ public void testGetTopTenSortOrder() { * {@link world.bentobox.level.LevelsManager#getRank(World, UUID)} */ @Test - public void testGetRank() { + void testGetRank() { lm.createAndCleanRankings(world); Map ttl = lm.getTopTenLists(); Map tt = ttl.get(world).getTopTen(); diff --git a/src/test/java/world/bentobox/level/PlaceholderManagerTest.java b/src/test/java/world/bentobox/level/PlaceholderManagerTest.java index 3b6b02d..8ea1179 100644 --- a/src/test/java/world/bentobox/level/PlaceholderManagerTest.java +++ b/src/test/java/world/bentobox/level/PlaceholderManagerTest.java @@ -42,7 +42,7 @@ * @author tastybento * */ -public class PlaceholderManagerTest extends CommonTestSetup { +class PlaceholderManagerTest extends CommonTestSetup { @Mock private GameModeAddon gm; @@ -81,7 +81,7 @@ public class PlaceholderManagerTest extends CommonTestSetup { */ @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); // Addon @@ -148,7 +148,7 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @@ -157,7 +157,7 @@ public void tearDown() throws Exception { * {@link world.bentobox.level.PlaceholderManager#PlaceholderManager(world.bentobox.level.Level)}. */ @Test - public void testPlaceholderManager() { + void testPlaceholderManager() { verify(addon).getPlugin(); } @@ -166,7 +166,7 @@ public void testPlaceholderManager() { * {@link world.bentobox.level.PlaceholderManager#registerPlaceholders(world.bentobox.bentobox.api.addons.GameModeAddon)}. */ @Test - public void testRegisterPlaceholders() { + void testRegisterPlaceholders() { phm.registerPlaceholders(gm); // Island Level verify(bpm).registerPlaceholder(eq(addon), eq("aoneblock_island_level"), any()); @@ -201,7 +201,7 @@ public void testRegisterPlaceholders() { * {@link world.bentobox.level.PlaceholderManager#getRankName(org.bukkit.World, int)}. */ @Test - public void testGetRankName() { + void testGetRankName() { // Test extremes assertEquals("tasty", phm.getRankName(world, 0, false)); assertEquals("vicky", phm.getRankName(world, 100, false)); @@ -218,7 +218,7 @@ public void testGetRankName() { * {@link world.bentobox.level.PlaceholderManager#getRankIslandName(org.bukkit.World, int)}. */ @Test - public void testGetRankIslandName() { + void testGetRankIslandName() { // Test extremes assertEquals("tasty's island", phm.getRankIslandName(world, 0, false)); assertEquals("vicky's island", phm.getRankIslandName(world, 100, false)); @@ -235,7 +235,7 @@ public void testGetRankIslandName() { * {@link world.bentobox.level.PlaceholderManager#getRankMembers(org.bukkit.World, int)}. */ @Test - public void testGetRankMembers() { + void testGetRankMembers() { // Test extremes check(1, phm.getRankMembers(world, 0, false)); check(2, phm.getRankMembers(world, 100, false)); @@ -256,7 +256,7 @@ void check(int indicator, String list) { * {@link world.bentobox.level.PlaceholderManager#getRankLevel(org.bukkit.World, int)}. */ @Test - public void testGetRankLevel() { + void testGetRankLevel() { // Test extremes assertEquals("100", phm.getRankLevel(world, 0, false)); assertEquals("91", phm.getRankLevel(world, 100, false)); @@ -272,7 +272,7 @@ public void testGetRankLevel() { * {@link world.bentobox.level.PlaceholderManager#getRankLevel(org.bukkit.World, int)}. */ @Test - public void testGetWeightedRankLevel() { + void testGetWeightedRankLevel() { // Test extremes assertEquals("100", phm.getRankLevel(world, 0, true)); assertEquals("91", phm.getRankLevel(world, 100, true)); @@ -288,7 +288,7 @@ public void testGetWeightedRankLevel() { * {@link world.bentobox.level.PlaceholderManager#getVisitedIslandLevel(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.api.user.User)}. */ @Test - public void testGetVisitedIslandLevelNullUser() { + void testGetVisitedIslandLevelNullUser() { assertEquals("", phm.getVisitedIslandLevel(gm, null)); } @@ -297,7 +297,7 @@ public void testGetVisitedIslandLevelNullUser() { * Test method for {@link world.bentobox.level.PlaceholderManager#getVisitedIslandLevel(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.api.user.User)}. */ @Test - public void testGetVisitedIslandLevelUserNotInWorld() { + void testGetVisitedIslandLevelUserNotInWorld() { // Another world when(user.getWorld()).thenReturn(mock(World.class)); assertEquals("", phm.getVisitedIslandLevel(gm, user)); @@ -309,7 +309,7 @@ public void testGetVisitedIslandLevelUserNotInWorld() { * {@link world.bentobox.level.PlaceholderManager#getVisitedIslandLevel(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.api.user.User)}. */ @Test - public void testGetVisitedIslandLevel() { + void testGetVisitedIslandLevel() { assertEquals("1234567", phm.getVisitedIslandLevel(gm, user)); } @@ -318,7 +318,7 @@ public void testGetVisitedIslandLevel() { * Test method for {@link world.bentobox.level.PlaceholderManager#getVisitedIslandLevel(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.api.user.User)}. */ @Test - public void testGetVisitedIslandLevelNoIsland() { + void testGetVisitedIslandLevelNoIsland() { when(im.getIslandAt(any(Location.class))).thenReturn(Optional.empty()); assertEquals("0", phm.getVisitedIslandLevel(gm, user)); diff --git a/src/test/java/world/bentobox/level/calculators/EquationEvaluatorTest.java b/src/test/java/world/bentobox/level/calculators/EquationEvaluatorTest.java index 9bcb5e2..d37be96 100644 --- a/src/test/java/world/bentobox/level/calculators/EquationEvaluatorTest.java +++ b/src/test/java/world/bentobox/level/calculators/EquationEvaluatorTest.java @@ -1,22 +1,22 @@ package world.bentobox.level.calculators; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.text.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test the equation evaluation */ -public class EquationEvaluatorTest { +class EquationEvaluatorTest { /** * Test method for {@link world.bentobox.level.calculators.EquationEvaluator#eval(java.lang.String)}. - * @throws ParseException + * @throws ParseException */ @Test - public void testEval() throws ParseException { + void testEval() throws ParseException { assertEquals(4D, EquationEvaluator.eval("2+2"), 0D); assertEquals(0D, EquationEvaluator.eval("2-2"), 0D); assertEquals(1D, EquationEvaluator.eval("2/2"), 0D); diff --git a/src/test/java/world/bentobox/level/calculators/ResultsTest.java b/src/test/java/world/bentobox/level/calculators/ResultsTest.java index fa0f906..66cf47d 100644 --- a/src/test/java/world/bentobox/level/calculators/ResultsTest.java +++ b/src/test/java/world/bentobox/level/calculators/ResultsTest.java @@ -14,30 +14,30 @@ /** * Tests for {@link Results} */ -public class ResultsTest { +class ResultsTest { private Results results; @BeforeEach - public void setUp() { + void setUp() { results = new Results(); } // --- State --- @Test - public void testDefaultStateIsAvailable() { + void testDefaultStateIsAvailable() { assertEquals(Result.AVAILABLE, results.getState()); } @Test - public void testConstructorWithInProgress() { + void testConstructorWithInProgress() { Results r = new Results(Result.IN_PROGRESS); assertEquals(Result.IN_PROGRESS, r.getState()); } @Test - public void testConstructorWithTimeout() { + void testConstructorWithTimeout() { Results r = new Results(Result.TIMEOUT); assertEquals(Result.TIMEOUT, r.getState()); } @@ -45,110 +45,110 @@ public void testConstructorWithTimeout() { // --- Level --- @Test - public void testSetAndGetLevel() { + void testSetAndGetLevel() { results.setLevel(42L); assertEquals(42L, results.getLevel()); } @Test - public void testDefaultLevelIsZero() { + void testDefaultLevelIsZero() { assertEquals(0L, results.getLevel()); } // --- Points to next level --- @Test - public void testSetAndGetPointsToNextLevel() { + void testSetAndGetPointsToNextLevel() { results.setPointsToNextLevel(100L); assertEquals(100L, results.getPointsToNextLevel()); } @Test - public void testDefaultPointsToNextLevelIsZero() { + void testDefaultPointsToNextLevelIsZero() { assertEquals(0L, results.getPointsToNextLevel()); } // --- Total points --- @Test - public void testSetAndGetTotalPoints() { + void testSetAndGetTotalPoints() { results.setTotalPoints(500L); assertEquals(500L, results.getTotalPoints()); } @Test - public void testDefaultTotalPointsIsZero() { + void testDefaultTotalPointsIsZero() { assertEquals(0L, results.getTotalPoints()); } // --- Death handicap --- @Test - public void testSetAndGetDeathHandicap() { + void testSetAndGetDeathHandicap() { results.setDeathHandicap(3); assertEquals(3, results.getDeathHandicap()); } @Test - public void testDefaultDeathHandicapIsZero() { + void testDefaultDeathHandicapIsZero() { assertEquals(0, results.getDeathHandicap()); } // --- Donated points --- @Test - public void testSetAndGetDonatedPoints() { + void testSetAndGetDonatedPoints() { results.setDonatedPoints(250L); assertEquals(250L, results.getDonatedPoints()); } @Test - public void testDefaultDonatedPointsIsZero() { + void testDefaultDonatedPointsIsZero() { assertEquals(0L, results.getDonatedPoints()); } // --- Initial count --- @Test - public void testSetAndGetInitialCount() { + void testSetAndGetInitialCount() { results.setInitialCount(999L); assertEquals(999L, results.getInitialCount()); } @Test - public void testDefaultInitialCountIsZero() { + void testDefaultInitialCountIsZero() { assertEquals(0L, results.getInitialCount()); } // --- Report --- @Test - public void testReportIsNullByDefault() { + void testReportIsNullByDefault() { assertNull(results.getReport()); } // --- Multisets --- @Test - public void testMdCountStartsEmpty() { + void testMdCountStartsEmpty() { assertNotNull(results.getMdCount()); assertTrue(results.getMdCount().isEmpty()); } @Test - public void testUwCountStartsEmpty() { + void testUwCountStartsEmpty() { assertNotNull(results.getUwCount()); assertTrue(results.getUwCount().isEmpty()); } @Test - public void testMdCountCanAddElements() { + void testMdCountCanAddElements() { results.getMdCount().add(Material.STONE, 5); assertEquals(5, results.getMdCount().count(Material.STONE)); } @Test - public void testUwCountCanAddElements() { + void testUwCountCanAddElements() { results.getUwCount().add(Material.SAND, 3); assertEquals(3, results.getUwCount().count(Material.SAND)); } @@ -156,7 +156,7 @@ public void testUwCountCanAddElements() { // --- Result enum --- @Test - public void testResultEnumValues() { + void testResultEnumValues() { assertEquals(3, Result.values().length); assertEquals(Result.IN_PROGRESS, Result.valueOf("IN_PROGRESS")); assertEquals(Result.AVAILABLE, Result.valueOf("AVAILABLE")); diff --git a/src/test/java/world/bentobox/level/commands/AdminLevelCommandTest.java b/src/test/java/world/bentobox/level/commands/AdminLevelCommandTest.java index 4080e62..170b639 100644 --- a/src/test/java/world/bentobox/level/commands/AdminLevelCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/AdminLevelCommandTest.java @@ -32,7 +32,7 @@ /** * Tests for {@link AdminLevelCommand} */ -public class AdminLevelCommandTest extends CommonTestSetup { +class AdminLevelCommandTest extends CommonTestSetup { @Mock private User user; @@ -49,7 +49,7 @@ public class AdminLevelCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(plugin.getPlayers()).thenReturn(pm); when(addon.getManager()).thenReturn(manager); @@ -79,30 +79,30 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("admin.level")); assertFalse(cmd.isOnlyPlayer()); } @Test - public void testExecuteConsoleScanIsland() { + void testExecuteConsoleScanIsland() { // Console with player name arg scans island assertTrue(cmd.execute(user, "level", List.of("tastybento"))); } @Test - public void testTabCompleteNoArgs() { + void testTabCompleteNoArgs() { Optional> result = cmd.tabComplete(user, "level", Collections.emptyList()); assertFalse(result.isPresent()); // empty args => return empty Optional } @Test - public void testTabCompleteWithArgs() { + void testTabCompleteWithArgs() { // getOnlinePlayerList calls Bukkit.getOnlinePlayers() — stub it to return empty list mockedUtil.when(() -> Util.getOnlinePlayerList(any())).thenReturn(List.of()); Optional> result = cmd.tabComplete(user, "level", List.of("tas")); diff --git a/src/test/java/world/bentobox/level/commands/AdminLevelStatusCommandTest.java b/src/test/java/world/bentobox/level/commands/AdminLevelStatusCommandTest.java index 2ecaed4..816165e 100644 --- a/src/test/java/world/bentobox/level/commands/AdminLevelStatusCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/AdminLevelStatusCommandTest.java @@ -24,7 +24,7 @@ /** * Tests for {@link AdminLevelStatusCommand} */ -public class AdminLevelStatusCommandTest extends CommonTestSetup { +class AdminLevelStatusCommandTest extends CommonTestSetup { @Mock private User user; @@ -35,7 +35,7 @@ public class AdminLevelStatusCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getPipeliner()).thenReturn(pipeliner); when(user.getTranslation(any())).thenAnswer(i -> i.getArgument(0, String.class)); @@ -44,26 +44,26 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("admin.levelstatus")); assertFalse(cmd.isOnlyPlayer()); assertEquals("levelstatus", cmd.getLabel()); } @Test - public void testExecuteShowsQueueSizeZero() { + void testExecuteShowsQueueSizeZero() { when(pipeliner.getIslandsInQueue()).thenReturn(0); assertTrue(cmd.execute(user, "levelstatus", Collections.emptyList())); verify(user).sendMessage(eq("admin.levelstatus.islands-in-queue"), eq(TextVariables.NUMBER), eq("0")); } @Test - public void testExecuteShowsQueueSizeNonZero() { + void testExecuteShowsQueueSizeNonZero() { when(pipeliner.getIslandsInQueue()).thenReturn(5); assertTrue(cmd.execute(user, "levelstatus", Collections.emptyList())); verify(user).sendMessage(eq("admin.levelstatus.islands-in-queue"), eq(TextVariables.NUMBER), eq("5")); diff --git a/src/test/java/world/bentobox/level/commands/AdminSetInitialLevelCommandTest.java b/src/test/java/world/bentobox/level/commands/AdminSetInitialLevelCommandTest.java index e1a8db3..2dbe46d 100644 --- a/src/test/java/world/bentobox/level/commands/AdminSetInitialLevelCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/AdminSetInitialLevelCommandTest.java @@ -26,7 +26,7 @@ /** * Tests for {@link AdminSetInitialLevelCommand} */ -public class AdminSetInitialLevelCommandTest extends CommonTestSetup { +class AdminSetInitialLevelCommandTest extends CommonTestSetup { @Mock private User user; @@ -39,7 +39,7 @@ public class AdminSetInitialLevelCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(plugin.getPlayers()).thenReturn(pm); when(addon.getManager()).thenReturn(manager); @@ -57,60 +57,60 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("admin.level.sethandicap")); assertFalse(cmd.isOnlyPlayer()); assertEquals("sethandicap", cmd.getLabel()); } @Test - public void testCanExecuteWrongArgCount() { + void testCanExecuteWrongArgCount() { assertFalse(cmd.canExecute(user, "sethandicap", List.of("player1"))); verify(user).sendMessage(eq("commands.help.header"), anyString(), anyString()); } @Test - public void testCanExecuteUnknownPlayer() { + void testCanExecuteUnknownPlayer() { when(pm.getUUID("unknown")).thenReturn(null); assertFalse(cmd.canExecute(user, "sethandicap", List.of("unknown", "100"))); verify(user).sendMessage(eq("general.errors.unknown-player"), eq(TextVariables.NAME), eq("unknown")); } @Test - public void testCanExecuteInvalidNumber() { + void testCanExecuteInvalidNumber() { assertFalse(cmd.canExecute(user, "sethandicap", List.of("tastybento", "notanumber"))); verify(user).sendMessage("admin.level.sethandicap.invalid-level"); } @Test - public void testCanExecutePlayerNoIsland() { + void testCanExecutePlayerNoIsland() { when(im.getIsland(any(), any(UUID.class))).thenReturn(null); assertFalse(cmd.canExecute(user, "sethandicap", List.of("tastybento", "100"))); verify(user).sendMessage("general.errors.player-has-no-island"); } @Test - public void testCanExecuteValid() { + void testCanExecuteValid() { assertTrue(cmd.canExecute(user, "sethandicap", List.of("tastybento", "100"))); } @Test - public void testCanExecuteValidWithPlus() { + void testCanExecuteValidWithPlus() { assertTrue(cmd.canExecute(user, "sethandicap", List.of("tastybento", "+50"))); } @Test - public void testCanExecuteValidWithMinus() { + void testCanExecuteValidWithMinus() { assertTrue(cmd.canExecute(user, "sethandicap", List.of("tastybento", "-20"))); } @Test - public void testExecuteSetAbsolute() { + void testExecuteSetAbsolute() { when(manager.getInitialCount(island)).thenReturn(50L); cmd.canExecute(user, "sethandicap", List.of("tastybento", "100")); assertTrue(cmd.execute(user, "sethandicap", List.of("tastybento", "100"))); @@ -118,7 +118,7 @@ public void testExecuteSetAbsolute() { } @Test - public void testExecuteSetPlus() { + void testExecuteSetPlus() { when(manager.getInitialCount(island)).thenReturn(50L); cmd.canExecute(user, "sethandicap", List.of("tastybento", "+10")); assertTrue(cmd.execute(user, "sethandicap", List.of("tastybento", "+10"))); @@ -126,7 +126,7 @@ public void testExecuteSetPlus() { } @Test - public void testExecuteSetMinus() { + void testExecuteSetMinus() { when(manager.getInitialCount(island)).thenReturn(50L); cmd.canExecute(user, "sethandicap", List.of("tastybento", "-20")); assertTrue(cmd.execute(user, "sethandicap", List.of("tastybento", "-20"))); diff --git a/src/test/java/world/bentobox/level/commands/AdminStatsCommandTest.java b/src/test/java/world/bentobox/level/commands/AdminStatsCommandTest.java index 55f4f55..02e8b3b 100644 --- a/src/test/java/world/bentobox/level/commands/AdminStatsCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/AdminStatsCommandTest.java @@ -30,7 +30,7 @@ /** * @author tastybento */ -public class AdminStatsCommandTest extends CommonTestSetup { +class AdminStatsCommandTest extends CommonTestSetup { @Mock private LevelsManager manager; @@ -44,7 +44,7 @@ public class AdminStatsCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); // Player manager @@ -69,7 +69,7 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @@ -78,7 +78,7 @@ public void tearDown() throws Exception { * {@link world.bentobox.level.commands.AdminStatsCommand#setup()}. */ @Test - public void testSetup() { + void testSetup() { assertEquals("bskyblock.admin.stats", asc.getPermission()); assertFalse(asc.isOnlyPlayer()); assertEquals("admin.stats.description", asc.getDescription()); @@ -90,7 +90,7 @@ public void testSetup() { * {@link world.bentobox.level.commands.AdminStatsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. */ @Test - public void testExecuteUserStringListOfString() { + void testExecuteUserStringListOfString() { assertFalse(asc.execute(user, "", List.of())); verify(user).sendMessage("admin.stats.title"); verify(user).sendMessage("admin.stats.no-data"); @@ -101,7 +101,7 @@ public void testExecuteUserStringListOfString() { * {@link world.bentobox.level.commands.AdminStatsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. */ @Test - public void testExecuteUserStringListOfStringLevels() { + void testExecuteUserStringListOfStringLevels() { Map map = new HashMap<>(); map.put(world, ttd); when(manager.getTopTenLists()).thenReturn(map); diff --git a/src/test/java/world/bentobox/level/commands/AdminTopCommandTest.java b/src/test/java/world/bentobox/level/commands/AdminTopCommandTest.java index e694a7f..c923c00 100644 --- a/src/test/java/world/bentobox/level/commands/AdminTopCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/AdminTopCommandTest.java @@ -26,7 +26,7 @@ /** * Tests for {@link AdminTopCommand} */ -public class AdminTopCommandTest extends CommonTestSetup { +class AdminTopCommandTest extends CommonTestSetup { @Mock private User user; @@ -39,7 +39,7 @@ public class AdminTopCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getManager()).thenReturn(manager); when(plugin.getPlayers()).thenReturn(pm); @@ -50,26 +50,26 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("admin.top")); assertFalse(cmd.isOnlyPlayer()); assertEquals("top", cmd.getLabel()); } @Test - public void testExecuteEmptyTopTen() { + void testExecuteEmptyTopTen() { when(manager.getTopTen(any(), any(Integer.class))).thenReturn(Collections.emptyMap()); assertTrue(cmd.execute(user, "top", Collections.emptyList())); verify(user).sendMessage("island.top.gui-title"); } @Test - public void testExecuteWithTopTenEntries() { + void testExecuteWithTopTenEntries() { Map topTen = new LinkedHashMap<>(); topTen.put(uuid.toString(), 100L); when(manager.getTopTen(any(), any(Integer.class))).thenReturn(topTen); @@ -84,7 +84,7 @@ public void testExecuteWithTopTenEntries() { } @Test - public void testExecuteSkipsIslandNotFound() { + void testExecuteSkipsIslandNotFound() { Map topTen = new LinkedHashMap<>(); topTen.put("some-island-id", 100L); when(manager.getTopTen(any(), any(Integer.class))).thenReturn(topTen); diff --git a/src/test/java/world/bentobox/level/commands/AdminTopRemoveCommandTest.java b/src/test/java/world/bentobox/level/commands/AdminTopRemoveCommandTest.java index 41a9c3a..6b0734d 100644 --- a/src/test/java/world/bentobox/level/commands/AdminTopRemoveCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/AdminTopRemoveCommandTest.java @@ -28,7 +28,7 @@ * @author tastybento * */ -public class AdminTopRemoveCommandTest extends CommonTestSetup { +class AdminTopRemoveCommandTest extends CommonTestSetup { @Mock private User user; @@ -43,7 +43,7 @@ public class AdminTopRemoveCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); // Player manager when(plugin.getPlayers()).thenReturn(pm); @@ -65,7 +65,7 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @@ -74,7 +74,7 @@ public void tearDown() throws Exception { * {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#AdminTopRemoveCommand(world.bentobox.level.Level, world.bentobox.bentobox.api.commands.CompositeCommand)}. */ @Test - public void testAdminTopRemoveCommand() { + void testAdminTopRemoveCommand() { assertEquals("remove", atrc.getLabel()); assertEquals("delete", atrc.getAliases().get(0)); } @@ -84,7 +84,7 @@ public void testAdminTopRemoveCommand() { * {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#setup()}. */ @Test - public void testSetup() { + void testSetup() { assertEquals("bskyblock.admin.top.remove", atrc.getPermission()); assertEquals("admin.top.remove.parameters", atrc.getParameters()); assertEquals("admin.top.remove.description", atrc.getDescription()); @@ -97,7 +97,7 @@ public void testSetup() { * {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. */ @Test - public void testCanExecuteWrongArgs() { + void testCanExecuteWrongArgs() { assertFalse(atrc.canExecute(user, "delete", Collections.emptyList())); verify(user).sendMessage("commands.help.header", TextVariables.LABEL, "BSkyBlock"); } @@ -106,7 +106,7 @@ public void testCanExecuteWrongArgs() { * Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. */ @Test - public void testCanExecuteUnknown() { + void testCanExecuteUnknown() { when(pm.getUser(anyString())).thenReturn(null); assertFalse(atrc.canExecute(user, "delete", Collections.singletonList("tastybento"))); verify(user).sendMessage("general.errors.unknown-player", TextVariables.NAME, "tastybento"); @@ -117,7 +117,7 @@ public void testCanExecuteUnknown() { * {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. */ @Test - public void testCanExecuteKnown() { + void testCanExecuteKnown() { assertTrue(atrc.canExecute(user, "delete", Collections.singletonList("tastybento"))); } @@ -126,7 +126,7 @@ public void testCanExecuteKnown() { * {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. */ @Test - public void testExecuteUserStringListOfString() { + void testExecuteUserStringListOfString() { testCanExecuteKnown(); assertTrue(atrc.execute(user, "delete", Collections.singletonList("tastybento"))); verify(manager).removeEntry(world, uuid.toString()); diff --git a/src/test/java/world/bentobox/level/commands/IslandDetailCommandTest.java b/src/test/java/world/bentobox/level/commands/IslandDetailCommandTest.java index 2985a0a..d57e1f3 100644 --- a/src/test/java/world/bentobox/level/commands/IslandDetailCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/IslandDetailCommandTest.java @@ -23,7 +23,7 @@ /** * Tests for {@link IslandDetailCommand} */ -public class IslandDetailCommandTest extends CommonTestSetup { +class IslandDetailCommandTest extends CommonTestSetup { @Mock private User user; @@ -32,7 +32,7 @@ public class IslandDetailCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(user.getUniqueId()).thenReturn(uuid); when(user.isPlayer()).thenReturn(true); @@ -43,26 +43,26 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("island.detail")); assertTrue(cmd.isOnlyPlayer()); assertEquals("detail", cmd.getLabel()); } @Test - public void testExecuteNoIsland() { + void testExecuteNoIsland() { when(im.getIsland(any(), any(User.class))).thenReturn(null); assertFalse(cmd.execute(user, "detail", Collections.emptyList())); verify(user).sendMessage("general.errors.player-has-no-island"); } @Test - public void testExecuteWithIslandOpensPanelAndReturnsTrue() { + void testExecuteWithIslandOpensPanelAndReturnsTrue() { try (MockedStatic mockedPanel = mockStatic(DetailsPanel.class)) { assertTrue(cmd.execute(user, "detail", Collections.emptyList())); mockedPanel.verify(() -> DetailsPanel.openPanel(any(), any(), any(User.class))); diff --git a/src/test/java/world/bentobox/level/commands/IslandDonateCommandTest.java b/src/test/java/world/bentobox/level/commands/IslandDonateCommandTest.java index bb1f195..7ba90bd 100644 --- a/src/test/java/world/bentobox/level/commands/IslandDonateCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/IslandDonateCommandTest.java @@ -36,7 +36,7 @@ /** * Tests for {@link IslandDonateCommand} */ -public class IslandDonateCommandTest extends CommonTestSetup { +class IslandDonateCommandTest extends CommonTestSetup { @Mock private User user; @@ -53,7 +53,7 @@ public class IslandDonateCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getManager()).thenReturn(manager); when(addon.getBlockConfig()).thenReturn(blockConfig); @@ -81,40 +81,40 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("island.donate")); assertTrue(cmd.isOnlyPlayer()); assertEquals("donate", cmd.getLabel()); } @Test - public void testExecuteNoIsland() { + void testExecuteNoIsland() { when(im.getIsland(any(), any(User.class))).thenReturn(null); assertFalse(cmd.execute(user, "donate", Collections.emptyList())); verify(user).sendMessage("general.errors.no-island"); } @Test - public void testExecuteNotOnIsland() { + void testExecuteNotOnIsland() { when(island.onIsland(any())).thenReturn(false); assertFalse(cmd.execute(user, "donate", Collections.emptyList())); verify(user).sendMessage("island.donate.must-be-on-island"); } @Test - public void testExecuteFlagDenied() { + void testExecuteFlagDenied() { when(island.isAllowed(any(User.class), any(Flag.class))).thenReturn(false); assertFalse(cmd.execute(user, "donate", Collections.emptyList())); verify(user).sendMessage("island.donate.no-permission"); } @Test - public void testExecuteNoArgsOpensDonationPanel() { + void testExecuteNoArgsOpensDonationPanel() { try (MockedStatic mockedPanel = mockStatic(DonationPanel.class)) { assertTrue(cmd.execute(user, "donate", Collections.emptyList())); mockedPanel.verify(() -> DonationPanel.openPanel(any(), any(), any(User.class), any())); @@ -122,7 +122,7 @@ public void testExecuteNoArgsOpensDonationPanel() { } @Test - public void testExecuteHandAirItem() { + void testExecuteHandAirItem() { ItemStack airStack = mock(ItemStack.class); when(airStack.getType()).thenReturn(Material.AIR); when(inventory.getItemInMainHand()).thenReturn(airStack); @@ -132,7 +132,7 @@ public void testExecuteHandAirItem() { } @Test - public void testExecuteHandNonBlockItem() { + void testExecuteHandNonBlockItem() { ItemStack swordStack = mock(ItemStack.class); when(swordStack.getType()).thenReturn(Material.DIAMOND_SWORD); when(inventory.getItemInMainHand()).thenReturn(swordStack); @@ -142,7 +142,7 @@ public void testExecuteHandNonBlockItem() { } @Test - public void testExecuteHandBlockNoValue() { + void testExecuteHandBlockNoValue() { // Material.STONE is a real block (isBlock()=true, isAir()=false) so no stubbing needed for those ItemStack stoneStack = mock(ItemStack.class); when(stoneStack.getType()).thenReturn(Material.STONE); @@ -155,7 +155,7 @@ public void testExecuteHandBlockNoValue() { } @Test - public void testTabCompleteNoArgs() { + void testTabCompleteNoArgs() { // When no args, should suggest "hand" var result = cmd.tabComplete(user, "donate", Collections.emptyList()); assertTrue(result.isPresent()); diff --git a/src/test/java/world/bentobox/level/commands/IslandLevelCommandTest.java b/src/test/java/world/bentobox/level/commands/IslandLevelCommandTest.java index 84e48f2..02ce93e 100644 --- a/src/test/java/world/bentobox/level/commands/IslandLevelCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/IslandLevelCommandTest.java @@ -32,7 +32,7 @@ /** * Tests for {@link IslandLevelCommand} */ -public class IslandLevelCommandTest extends CommonTestSetup { +class IslandLevelCommandTest extends CommonTestSetup { @Mock private User user; @@ -49,7 +49,7 @@ public class IslandLevelCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(plugin.getPlayers()).thenReturn(pm); when(addon.getManager()).thenReturn(manager); @@ -75,31 +75,31 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("island.level")); } @Test - public void testExecuteConsoleNoArgsShowsError() { + void testExecuteConsoleNoArgsShowsError() { when(user.isPlayer()).thenReturn(false); assertFalse(cmd.execute(user, "level", Collections.emptyList())); verify(user).sendMessage("general.errors.use-in-game"); } @Test - public void testExecuteUnknownPlayerArg() { + void testExecuteUnknownPlayerArg() { when(pm.getUUID(anyString())).thenReturn(null); assertFalse(cmd.execute(user, "level", List.of("unknownplayer"))); verify(user).sendMessage(eq("general.errors.unknown-player"), eq(TextVariables.NAME), anyString()); } @Test - public void testExecuteOtherPlayerLevelRequest() { + void testExecuteOtherPlayerLevelRequest() { UUID otherUUID = UUID.randomUUID(); when(pm.getUUID("otherguy")).thenReturn(otherUUID); when(manager.getIslandLevelString(any(), eq(otherUUID))).thenReturn("10"); @@ -109,14 +109,14 @@ public void testExecuteOtherPlayerLevelRequest() { } @Test - public void testExecuteSelfNoIsland() { + void testExecuteSelfNoIsland() { when(im.getIsland(any(), any(UUID.class))).thenReturn(null); assertFalse(cmd.execute(user, "level", Collections.emptyList())); verify(user).sendMessage("general.errors.player-has-no-island"); } @Test - public void testExecuteSelfWithIslandSendsCalculating() { + void testExecuteSelfWithIslandSendsCalculating() { Results results = new Results(Result.AVAILABLE); when(manager.calculateLevel(any(), any())).thenReturn(CompletableFuture.completedFuture(results)); when(manager.getIslandLevelString(any(), any())).thenReturn("5"); @@ -126,7 +126,7 @@ public void testExecuteSelfWithIslandSendsCalculating() { } @Test - public void testExecuteSelfResultInProgress() { + void testExecuteSelfResultInProgress() { Results results = new Results(Result.IN_PROGRESS); when(manager.calculateLevel(any(), any())).thenReturn(CompletableFuture.completedFuture(results)); @@ -135,7 +135,7 @@ public void testExecuteSelfResultInProgress() { } @Test - public void testExecuteSelfResultTimeout() { + void testExecuteSelfResultTimeout() { Results results = new Results(Result.TIMEOUT); when(manager.calculateLevel(any(), any())).thenReturn(CompletableFuture.completedFuture(results)); @@ -144,7 +144,7 @@ public void testExecuteSelfResultTimeout() { } @Test - public void testExecuteSelfNullResultIsIgnored() { + void testExecuteSelfNullResultIsIgnored() { when(manager.calculateLevel(any(), any())).thenReturn(CompletableFuture.completedFuture(null)); // Should not throw assertTrue(cmd.execute(user, "level", Collections.emptyList())); diff --git a/src/test/java/world/bentobox/level/commands/IslandTopCommandTest.java b/src/test/java/world/bentobox/level/commands/IslandTopCommandTest.java index 0b3d807..1c95036 100644 --- a/src/test/java/world/bentobox/level/commands/IslandTopCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/IslandTopCommandTest.java @@ -22,7 +22,7 @@ /** * Tests for {@link IslandTopCommand} */ -public class IslandTopCommandTest extends CommonTestSetup { +class IslandTopCommandTest extends CommonTestSetup { @Mock private User user; @@ -31,7 +31,7 @@ public class IslandTopCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(user.getUniqueId()).thenReturn(uuid); when(user.isPlayer()).thenReturn(true); @@ -41,19 +41,19 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("island.top")); assertTrue(cmd.isOnlyPlayer()); assertEquals("top", cmd.getLabel()); } @Test - public void testExecuteOpensPanelAndReturnsTrue() { + void testExecuteOpensPanelAndReturnsTrue() { try (MockedStatic mockedPanel = mockStatic(TopLevelPanel.class)) { assertTrue(cmd.execute(user, "top", Collections.emptyList())); mockedPanel.verify(() -> TopLevelPanel.openPanel(any(), any(User.class), any(), anyString())); diff --git a/src/test/java/world/bentobox/level/commands/IslandValueCommandTest.java b/src/test/java/world/bentobox/level/commands/IslandValueCommandTest.java index a693cb1..350dc85 100644 --- a/src/test/java/world/bentobox/level/commands/IslandValueCommandTest.java +++ b/src/test/java/world/bentobox/level/commands/IslandValueCommandTest.java @@ -35,7 +35,7 @@ /** * Tests for {@link IslandValueCommand} */ -public class IslandValueCommandTest extends CommonTestSetup { +class IslandValueCommandTest extends CommonTestSetup { @Mock private User user; @@ -56,7 +56,7 @@ public class IslandValueCommandTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getBlockConfig()).thenReturn(blockConfig); when(addon.getManager()).thenReturn(manager); @@ -83,19 +83,19 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testSetup() { + void testSetup() { assertTrue(cmd.getPermission().contains("island.value")); assertTrue(cmd.isOnlyPlayer()); assertEquals("value", cmd.getLabel()); } @Test - public void testExecuteNoArgsOpenValuePanel() { + void testExecuteNoArgsOpenValuePanel() { try (MockedStatic mockedPanel = mockStatic(ValuePanel.class)) { assertTrue(cmd.execute(user, "value", Collections.emptyList())); mockedPanel.verify(() -> ValuePanel.openPanel(any(), any(), any(User.class))); @@ -103,19 +103,19 @@ public void testExecuteNoArgsOpenValuePanel() { } @Test - public void testExecuteTooManyArgsShowsHelp() { + void testExecuteTooManyArgsShowsHelp() { assertFalse(cmd.execute(user, "value", List.of("STONE", "extra"))); } @Test - public void testExecuteUnknownMaterial() { + void testExecuteUnknownMaterial() { assertTrue(cmd.execute(user, "value", List.of("NOTAMATERIAL"))); // Sends unknown-item message via Utils.sendMessage verify(user, times(2)).getTranslation(anyString()); // keyword lookup + unknown item message } @Test - public void testTabCompleteEmptyArgsReturnsEmpty() { + void testTabCompleteEmptyArgsReturnsEmpty() { var result = cmd.tabComplete(user, "value", Collections.emptyList()); assertFalse(result.isPresent()); } diff --git a/src/test/java/world/bentobox/level/listeners/IslandActivitiesListenersTest.java b/src/test/java/world/bentobox/level/listeners/IslandActivitiesListenersTest.java index 2f602eb..d0d80fb 100644 --- a/src/test/java/world/bentobox/level/listeners/IslandActivitiesListenersTest.java +++ b/src/test/java/world/bentobox/level/listeners/IslandActivitiesListenersTest.java @@ -31,7 +31,7 @@ /** * Tests for {@link IslandActivitiesListeners} */ -public class IslandActivitiesListenersTest extends CommonTestSetup { +class IslandActivitiesListenersTest extends CommonTestSetup { @Mock private LevelsManager manager; @@ -44,7 +44,7 @@ public class IslandActivitiesListenersTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getManager()).thenReturn(manager); when(addon.getPipeliner()).thenReturn(pipeliner); @@ -65,14 +65,14 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } // --- IslandCreatedEvent --- @Test - public void testOnNewIslandCreatedZeroNewIslandLevelsTrue() { + void testOnNewIslandCreatedZeroNewIslandLevelsTrue() { when(settings.isZeroNewIslandLevels()).thenReturn(true); IslandCreatedEvent event = new IslandCreatedEvent(island, uuid, false, location); listener.onNewIsland(event); @@ -81,7 +81,7 @@ public void testOnNewIslandCreatedZeroNewIslandLevelsTrue() { } @Test - public void testOnNewIslandCreatedZeroNewIslandLevelsFalse() { + void testOnNewIslandCreatedZeroNewIslandLevelsFalse() { when(settings.isZeroNewIslandLevels()).thenReturn(false); IslandCreatedEvent event = new IslandCreatedEvent(island, uuid, false, location); listener.onNewIsland(event); @@ -91,7 +91,7 @@ public void testOnNewIslandCreatedZeroNewIslandLevelsFalse() { // --- IslandResettedEvent --- @Test - public void testOnIslandResettedZeroNewIslandLevelsTrue() { + void testOnIslandResettedZeroNewIslandLevelsTrue() { when(settings.isZeroNewIslandLevels()).thenReturn(true); IslandResettedEvent event = new IslandResettedEvent(island, uuid, false, location, island); listener.onNewIsland(event); @@ -99,7 +99,7 @@ public void testOnIslandResettedZeroNewIslandLevelsTrue() { } @Test - public void testOnIslandResettedZeroNewIslandLevelsFalse() { + void testOnIslandResettedZeroNewIslandLevelsFalse() { when(settings.isZeroNewIslandLevels()).thenReturn(false); IslandResettedEvent event = new IslandResettedEvent(island, uuid, false, location, island); listener.onNewIsland(event); @@ -109,14 +109,14 @@ public void testOnIslandResettedZeroNewIslandLevelsFalse() { // --- IslandPreclearEvent (remove from top ten) --- @Test - public void testOnIslandDeleteRemovesFromTopTen() { + void testOnIslandDeleteRemovesFromTopTen() { IslandPreclearEvent event = new IslandPreclearEvent(island, uuid, false, location, island); listener.onIslandDelete(event); verify(manager).removeEntry(world, uuid.toString()); } @Test - public void testOnIslandDeleteNoWorldNoAction() { + void testOnIslandDeleteNoWorldNoAction() { when(island.getWorld()).thenReturn(null); IslandPreclearEvent event = new IslandPreclearEvent(island, uuid, false, location, island); listener.onIslandDelete(event); @@ -126,7 +126,7 @@ public void testOnIslandDeleteNoWorldNoAction() { // --- IslandDeleteEvent --- @Test - public void testOnIslandDeletedCallsDeleteIsland() { + void testOnIslandDeletedCallsDeleteIsland() { IslandDeleteEvent event = new IslandDeleteEvent(island, uuid, false, location); listener.onIslandDeleted(event); verify(manager).deleteIsland(uuid.toString()); @@ -135,7 +135,7 @@ public void testOnIslandDeletedCallsDeleteIsland() { // --- IslandUnregisteredEvent --- @Test - public void testOnIslandUnregisteredRemovesFromTopTen() { + void testOnIslandUnregisteredRemovesFromTopTen() { IslandUnregisteredEvent event = new IslandUnregisteredEvent(island, uuid, false, location); listener.onIsland(event); verify(manager).removeEntry(world, uuid.toString()); @@ -144,7 +144,7 @@ public void testOnIslandUnregisteredRemovesFromTopTen() { // --- TeamSetownerEvent --- @Test - public void testOnNewIslandOwnerRemovesEntry() { + void testOnNewIslandOwnerRemovesEntry() { TeamSetownerEvent event = new TeamSetownerEvent(island, UUID.randomUUID(), false, location); listener.onNewIslandOwner(event); verify(manager).removeEntry(world, uuid.toString()); diff --git a/src/test/java/world/bentobox/level/listeners/JoinLeaveListenerTest.java b/src/test/java/world/bentobox/level/listeners/JoinLeaveListenerTest.java index c8fc449..7856f0a 100644 --- a/src/test/java/world/bentobox/level/listeners/JoinLeaveListenerTest.java +++ b/src/test/java/world/bentobox/level/listeners/JoinLeaveListenerTest.java @@ -27,7 +27,7 @@ /** * Tests for {@link JoinLeaveListener} */ -public class JoinLeaveListenerTest extends CommonTestSetup { +class JoinLeaveListenerTest extends CommonTestSetup { @Mock private LevelsManager manager; @@ -44,7 +44,7 @@ public class JoinLeaveListenerTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getManager()).thenReturn(manager); when(addon.getSettings()).thenReturn(settings); @@ -71,12 +71,12 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testCalcOnLoginFalseDoesNotCalculate() { + void testCalcOnLoginFalseDoesNotCalculate() { when(settings.isCalcOnLogin()).thenReturn(false); PlayerJoinEvent event = new PlayerJoinEvent(player, "joined"); listener.onPlayerJoin(event); @@ -84,7 +84,7 @@ public void testCalcOnLoginFalseDoesNotCalculate() { } @Test - public void testCalcOnLoginTrueWithIslandCalculates() { + void testCalcOnLoginTrueWithIslandCalculates() { when(settings.isCalcOnLogin()).thenReturn(true); PlayerJoinEvent event = new PlayerJoinEvent(player, "joined"); listener.onPlayerJoin(event); @@ -92,7 +92,7 @@ public void testCalcOnLoginTrueWithIslandCalculates() { } @Test - public void testCalcOnLoginTrueNoIslandDoesNotCalculate() { + void testCalcOnLoginTrueNoIslandDoesNotCalculate() { when(settings.isCalcOnLogin()).thenReturn(true); when(im.getIsland(any(World.class), any(UUID.class))).thenReturn(null); PlayerJoinEvent event = new PlayerJoinEvent(player, "joined"); @@ -101,7 +101,7 @@ public void testCalcOnLoginTrueNoIslandDoesNotCalculate() { } @Test - public void testCalcOnLoginTrueExcludedGameModeSkips() { + void testCalcOnLoginTrueExcludedGameModeSkips() { when(settings.isCalcOnLogin()).thenReturn(true); when(settings.getGameModes()).thenReturn(List.of("BSkyBlock")); // exclude this game mode PlayerJoinEvent event = new PlayerJoinEvent(player, "joined"); diff --git a/src/test/java/world/bentobox/level/listeners/MigrationListenerTest.java b/src/test/java/world/bentobox/level/listeners/MigrationListenerTest.java index e9c488a..51ee2b0 100644 --- a/src/test/java/world/bentobox/level/listeners/MigrationListenerTest.java +++ b/src/test/java/world/bentobox/level/listeners/MigrationListenerTest.java @@ -15,7 +15,7 @@ /** * Tests for {@link MigrationListener} */ -public class MigrationListenerTest extends CommonTestSetup { +class MigrationListenerTest extends CommonTestSetup { @Mock private LevelsManager manager; @@ -24,7 +24,7 @@ public class MigrationListenerTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getManager()).thenReturn(manager); listener = new MigrationListener(addon); @@ -32,12 +32,12 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testOnBentoBoxReadyCallsLoadTopTens() { + void testOnBentoBoxReadyCallsLoadTopTens() { BentoBoxReadyEvent event = new BentoBoxReadyEvent(); listener.onBentoBoxReady(event); verify(manager).loadTopTens(); diff --git a/src/test/java/world/bentobox/level/objects/IslandLevelsTest.java b/src/test/java/world/bentobox/level/objects/IslandLevelsTest.java index f59e5c0..0c62fe5 100644 --- a/src/test/java/world/bentobox/level/objects/IslandLevelsTest.java +++ b/src/test/java/world/bentobox/level/objects/IslandLevelsTest.java @@ -17,31 +17,31 @@ /** * Tests for {@link IslandLevels} */ -public class IslandLevelsTest { +class IslandLevelsTest { private static final String ISLAND_ID = "test-island-uuid"; private IslandLevels islandLevels; @BeforeEach - public void setUp() { + void setUp() { MockBukkit.mock(); islandLevels = new IslandLevels(ISLAND_ID); } @AfterEach - public void tearDown() { + void tearDown() { MockBukkit.unmock(); } // --- UniqueId --- @Test - public void testGetUniqueId() { + void testGetUniqueId() { assertEquals(ISLAND_ID, islandLevels.getUniqueId()); } @Test - public void testSetUniqueId() { + void testSetUniqueId() { islandLevels.setUniqueId("new-id"); assertEquals("new-id", islandLevels.getUniqueId()); } @@ -49,14 +49,14 @@ public void testSetUniqueId() { // --- Level with max tracking --- @Test - public void testSetLevelUpdatesMaxLevel() { + void testSetLevelUpdatesMaxLevel() { islandLevels.setLevel(5L); assertEquals(5L, islandLevels.getLevel()); assertEquals(5L, islandLevels.getMaxLevel()); } @Test - public void testMaxLevelDoesNotDecrease() { + void testMaxLevelDoesNotDecrease() { islandLevels.setLevel(10L); islandLevels.setLevel(3L); assertEquals(3L, islandLevels.getLevel()); @@ -64,14 +64,14 @@ public void testMaxLevelDoesNotDecrease() { } @Test - public void testMaxLevelUpdatesWhenHigher() { + void testMaxLevelUpdatesWhenHigher() { islandLevels.setLevel(5L); islandLevels.setLevel(8L); assertEquals(8L, islandLevels.getMaxLevel()); } @Test - public void testDefaultLevelIsZero() { + void testDefaultLevelIsZero() { assertEquals(0L, islandLevels.getLevel()); assertEquals(0L, islandLevels.getMaxLevel()); } @@ -79,7 +79,7 @@ public void testDefaultLevelIsZero() { // --- Points to next level --- @Test - public void testPointsToNextLevel() { + void testPointsToNextLevel() { islandLevels.setPointsToNextLevel(150L); assertEquals(150L, islandLevels.getPointsToNextLevel()); } @@ -87,7 +87,7 @@ public void testPointsToNextLevel() { // --- Total points --- @Test - public void testTotalPoints() { + void testTotalPoints() { islandLevels.setTotalPoints(9999L); assertEquals(9999L, islandLevels.getTotalPoints()); } @@ -95,13 +95,13 @@ public void testTotalPoints() { // --- Initial count --- @Test - public void testInitialCount() { + void testInitialCount() { islandLevels.setInitialCount(500L); assertEquals(500L, islandLevels.getInitialCount()); } @Test - public void testInitialCountDefaultNull() { + void testInitialCountDefaultNull() { // New island has null initial count (not yet set) assertEquals(null, islandLevels.getInitialCount()); } @@ -109,7 +109,7 @@ public void testInitialCountDefaultNull() { // --- convertMap via getMdCount / getUwCount --- @Test - public void testGetMdCountConvertsStringToMaterial() { + void testGetMdCountConvertsStringToMaterial() { Map map = new HashMap<>(); map.put("STONE", 10); islandLevels.setMdCount(map); @@ -120,7 +120,7 @@ public void testGetMdCountConvertsStringToMaterial() { } @Test - public void testGetMdCountConvertsStringToEntityType() { + void testGetMdCountConvertsStringToEntityType() { Map map = new HashMap<>(); map.put("ZOMBIE", 5); islandLevels.setMdCount(map); @@ -131,7 +131,7 @@ public void testGetMdCountConvertsStringToEntityType() { } @Test - public void testGetMdCountKeepsUnknownStringAsIs() { + void testGetMdCountKeepsUnknownStringAsIs() { Map map = new HashMap<>(); map.put("unknown_xyz_block", 3); islandLevels.setMdCount(map); @@ -142,7 +142,7 @@ public void testGetMdCountKeepsUnknownStringAsIs() { } @Test - public void testGetMdCountKeepsNonStringKeyAsIs() { + void testGetMdCountKeepsNonStringKeyAsIs() { Map map = new HashMap<>(); map.put(Material.DIRT, 7); islandLevels.setMdCount(map); @@ -153,7 +153,7 @@ public void testGetMdCountKeepsNonStringKeyAsIs() { } @Test - public void testGetUwCountConvertsStringToMaterial() { + void testGetUwCountConvertsStringToMaterial() { Map map = new HashMap<>(); map.put("SAND", 4); islandLevels.setUwCount(map); @@ -166,36 +166,36 @@ public void testGetUwCountConvertsStringToMaterial() { // --- Donation API --- @Test - public void testGetDonatedBlocksReturnsEmptyMapByDefault() { + void testGetDonatedBlocksReturnsEmptyMapByDefault() { assertNotNull(islandLevels.getDonatedBlocks()); assertTrue(islandLevels.getDonatedBlocks().isEmpty()); } @Test - public void testGetDonationLogReturnsEmptyListByDefault() { + void testGetDonationLogReturnsEmptyListByDefault() { assertNotNull(islandLevels.getDonationLog()); assertTrue(islandLevels.getDonationLog().isEmpty()); } @Test - public void testGetDonatedPointsReturnsZeroByDefault() { + void testGetDonatedPointsReturnsZeroByDefault() { assertEquals(0L, islandLevels.getDonatedPoints()); } @Test - public void testAddDonationAccumulatesBlocks() { + void testAddDonationAccumulatesBlocks() { islandLevels.addDonation("donor-uuid", "STONE", 5, 25L); assertEquals(5, islandLevels.getDonatedBlocks().get("STONE")); } @Test - public void testAddDonationAccumulatesPoints() { + void testAddDonationAccumulatesPoints() { islandLevels.addDonation("donor-uuid", "STONE", 5, 25L); assertEquals(25L, islandLevels.getDonatedPoints()); } @Test - public void testAddDonationAppendsToLog() { + void testAddDonationAppendsToLog() { islandLevels.addDonation("donor-uuid", "STONE", 5, 25L); assertEquals(1, islandLevels.getDonationLog().size()); IslandLevels.DonationRecord record = islandLevels.getDonationLog().get(0); @@ -206,7 +206,7 @@ public void testAddDonationAppendsToLog() { } @Test - public void testAddDonationMultipleCallsMergeCounts() { + void testAddDonationMultipleCallsMergeCounts() { islandLevels.addDonation("donor-uuid", "STONE", 3, 15L); islandLevels.addDonation("donor-uuid", "STONE", 7, 35L); assertEquals(10, islandLevels.getDonatedBlocks().get("STONE")); @@ -215,7 +215,7 @@ public void testAddDonationMultipleCallsMergeCounts() { } @Test - public void testAddDonationDifferentMaterials() { + void testAddDonationDifferentMaterials() { islandLevels.addDonation("donor-uuid", "STONE", 3, 15L); islandLevels.addDonation("donor-uuid", "DIRT", 2, 4L); assertEquals(3, islandLevels.getDonatedBlocks().get("STONE")); @@ -226,7 +226,7 @@ public void testAddDonationDifferentMaterials() { // --- Deprecated initialLevel backwards-compat --- @Test - public void testDeprecatedInitialLevel() { + void testDeprecatedInitialLevel() { islandLevels.setInitialLevel(100L); assertEquals(100L, islandLevels.getInitialLevel()); } diff --git a/src/test/java/world/bentobox/level/objects/TopTenDataTest.java b/src/test/java/world/bentobox/level/objects/TopTenDataTest.java index e115f5b..4d6d070 100644 --- a/src/test/java/world/bentobox/level/objects/TopTenDataTest.java +++ b/src/test/java/world/bentobox/level/objects/TopTenDataTest.java @@ -16,26 +16,26 @@ /** * Tests for {@link TopTenData} */ -public class TopTenDataTest { +class TopTenDataTest { private World world; private TopTenData topTenData; @BeforeEach - public void setUp() { + void setUp() { world = mock(World.class); when(world.getName()).thenReturn("BSkyBlock_world"); topTenData = new TopTenData(world); } @Test - public void testTopTenStartsEmpty() { + void testTopTenStartsEmpty() { assertNotNull(topTenData.getTopTen()); assertTrue(topTenData.getTopTen().isEmpty()); } @Test - public void testSetAndGetTopTen() { + void testSetAndGetTopTen() { Map newMap = new ConcurrentHashMap<>(); newMap.put("island-uuid-1", 100L); newMap.put("island-uuid-2", 200L); @@ -48,13 +48,13 @@ public void testSetAndGetTopTen() { } @Test - public void testTopTenIsMutable() { + void testTopTenIsMutable() { topTenData.getTopTen().put("new-island", 50L); assertEquals(50L, topTenData.getTopTen().get("new-island")); } @Test - public void testSetTopTenReplacesExisting() { + void testSetTopTenReplacesExisting() { topTenData.getTopTen().put("old-island", 10L); Map newMap = new ConcurrentHashMap<>(); newMap.put("new-island", 500L); diff --git a/src/test/java/world/bentobox/level/panels/DonationPanelLayoutTest.java b/src/test/java/world/bentobox/level/panels/DonationPanelLayoutTest.java new file mode 100644 index 0000000..ff80f76 --- /dev/null +++ b/src/test/java/world/bentobox/level/panels/DonationPanelLayoutTest.java @@ -0,0 +1,326 @@ +package world.bentobox.level.panels; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.util.List; + +import org.bukkit.Material; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.inventory.ItemStack; +import org.junit.jupiter.api.Test; + +import world.bentobox.bentobox.api.panels.Panel; +import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord; +import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord; +import world.bentobox.bentobox.api.panels.reader.PanelTemplateRecord.TemplateItem; + +/** + * Pure layout-resolution tests for {@link DonationPanelLayout}. Avoids MockBukkit + * by stubbing only the {@link ItemStack#getType()} contract that the resolver + * uses. + */ +class DonationPanelLayoutTest { + + private static ItemStack iconOf(Material mat) { + ItemStack stack = mock(ItemStack.class); + when(stack.getType()).thenReturn(mat); + when(stack.clone()).thenReturn(stack); + return stack; + } + + private static ItemTemplateRecord namedButton(Material icon, String type, String title) { + ItemTemplateRecord rec = new ItemTemplateRecord(iconOf(icon), title, null, null); + rec.addData("type", type); + return rec; + } + + private static PanelTemplateRecord template(TemplateItem border, int forcedRows) { + boolean[] forced = new boolean[6]; + for (int i = 0; i < forcedRows && i < 6; i++) forced[i] = true; + return new PanelTemplateRecord(Panel.Type.INVENTORY, "title-key", border, null, forced); + } + + private static TemplateItem border() { + return new TemplateItem(iconOf(Material.BLACK_STAINED_GLASS_PANE)); + } + + @Test + void nullTemplateUsesDefaults() { + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(null); + assertEquals(DonationPanelLayout.DEFAULT_SIZE, layout.size); + assertEquals(DonationPanelLayout.DEFAULT_INFO_SLOT, layout.infoSlot); + assertEquals(DonationPanelLayout.DEFAULT_CANCEL_SLOT, layout.cancelSlot); + assertEquals(DonationPanelLayout.DEFAULT_PREVIEW_SLOT, layout.previewSlot); + assertEquals(DonationPanelLayout.DEFAULT_CONFIRM_SLOT, layout.confirmSlot); + assertArrayEquals(DonationPanelLayout.DEFAULT_DONATION_SLOTS, layout.donationSlots); + assertEquals(DonationPanelLayout.DEFAULT_BORDER_MATERIAL, layout.borderMaterial); + } + + @Test + void defaultTemplateMatchesLegacyLayout() { + // Mirrors the shipped panels/donation_panel.yml: 4 forced rows, INFO@(1,5), + // CANCEL@(4,2), PREVIEW@(4,5), CONFIRM@(4,8), with a border. + PanelTemplateRecord t = template(border(), 4); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(3, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals(36, layout.size); + assertEquals(4, layout.infoSlot); + assertEquals(28, layout.cancelSlot); + assertEquals(31, layout.previewSlot); + assertEquals(34, layout.confirmSlot); + assertArrayEquals(DonationPanelLayout.DEFAULT_DONATION_SLOTS, layout.donationSlots); + assertEquals(Material.BLACK_STAINED_GLASS_PANE, layout.borderMaterial); + assertEquals(Material.BOOK, layout.infoMaterial); + assertEquals(Material.RED_STAINED_GLASS_PANE, layout.cancelMaterial); + assertEquals(Material.EXPERIENCE_BOTTLE, layout.previewMaterial); + assertEquals(Material.LIME_STAINED_GLASS_PANE, layout.confirmMaterial); + } + + @Test + void sixRowTemplateExpandsDonationGrid() { + PanelTemplateRecord t = template(border(), 6); + // Keep buttons in row 1 / row 6 corners so the middle 4 rows are donation + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(5, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(5, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(5, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals(54, layout.size); + // 4 inner rows of 7 columns each = 28 donation slots + assertEquals(28, layout.donationSlots.length); + // Spot check: first inner cell is slot 10, last is slot 43 + assertEquals(10, layout.donationSlots[0]); + assertEquals(43, layout.donationSlots[layout.donationSlots.length - 1]); + } + + @Test + void singleRowTemplateHasNoDonationSlots() { + // Pathological but should not crash: a 1-row template with all 4 buttons + // packed into row 1. Border consumes the rest, leaving zero donation slots. + PanelTemplateRecord t = template(border(), 1); + t.addButtonTemplate(0, 1, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(0, 3, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(0, 5, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(0, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals(9, layout.size); + assertEquals(0, layout.donationSlots.length); + } + + @Test + void noBorderTemplateTurnsOuterRingIntoDonationSlots() { + // No border item: every cell that isn't a named button becomes a donation slot. + PanelTemplateRecord t = template(null, 4); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(3, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals(36, layout.size); + // 36 cells minus 4 named buttons = 32 donation slots + assertEquals(32, layout.donationSlots.length); + // borderMaterial is AIR sentinel when no border so the constructor skips fill + assertEquals(Material.AIR, layout.borderMaterial); + } + + @Test + void missingButtonFallsBackToDefaults() { + // Only 3 of the 4 required buttons defined; the resolver must not silently + // produce a UI with no PREVIEW pane — instead it falls back to defaults. + PanelTemplateRecord t = template(border(), 4); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + // PREVIEW omitted on purpose + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals(DonationPanelLayout.DEFAULT_SIZE, layout.size); + assertEquals(DonationPanelLayout.DEFAULT_PREVIEW_SLOT, layout.previewSlot); + } + + @Test + void rowCountInferredFromContentWhenNoForcedRows() { + // No force-shown set, but content occupies rows 1 and 5. + PanelTemplateRecord t = template(border(), 0); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(4, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(4, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(4, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals(45, layout.size); + // The middle 3 rows (rows 2-4 = slots 9-35), inner 7 cols each = 21 donation slots + assertEquals(21, layout.donationSlots.length); + } + + @Test + void titleOverridesArePropagated() { + PanelTemplateRecord t = template(border(), 4); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", "custom.cancel")); + t.addButtonTemplate(3, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", "custom.confirm")); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals("custom.cancel", layout.cancelTitleOverride); + assertEquals("custom.confirm", layout.confirmTitleOverride); + } + + @Test + void unknownDataTypesAreIgnored() { + // Spurious data.type values should not corrupt slot resolution. + PanelTemplateRecord t = template(border(), 4); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(1, 1, namedButton(Material.PAPER, "BOGUS", null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(3, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals(36, layout.size); + // The BOGUS slot at row 2 col 2 (slot 10) is occupied by a non-recognised + // template item, so it gets skipped from the donation slot set. + assertNotEquals(0, layout.donationSlots.length); + for (int s : layout.donationSlots) { + assertNotEquals(10, s, "slot 10 must be reserved by the unknown template entry"); + } + } + + @Test + void decorativeItemsWithUnknownTypeAreStored() { + // An entry with BOGUS type should appear in decorativeItems so + // DonationPanel can place it visibly in the inventory. + PanelTemplateRecord t = template(border(), 4); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(1, 1, namedButton(Material.PAPER, "BOGUS", null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(3, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertTrue(layout.decorativeItems.containsKey(10), + "slot 10 must be in decorativeItems so it gets rendered"); + assertEquals(Material.PAPER, layout.decorativeItems.get(10).getType()); + } + + @Test + void decorativeItemsWithNoTypeAreStored() { + // An entry that has NO data section at all should also appear in + // decorativeItems. + PanelTemplateRecord t = template(border(), 4); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + // Row 2 col 1 (slot 9): plain item with no data.type + ItemStack diamond = mock(ItemStack.class); + when(diamond.getType()).thenReturn(Material.DIAMOND); + when(diamond.clone()).thenReturn(diamond); + t.addButtonTemplate(1, 0, new ItemTemplateRecord(diamond, null, null, null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(3, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertTrue(layout.decorativeItems.containsKey(9), + "slot 9 must be in decorativeItems (no data.type set)"); + assertEquals(Material.DIAMOND, layout.decorativeItems.get(9).getType()); + } + + @Test + void defaultsUsesDefaultTitleRef() { + DonationPanelLayout layout = DonationPanelLayout.defaults(); + assertEquals(DonationPanelLayout.DEFAULT_TITLE_REF, layout.panelTitle); + } + + @Test + void templateTitleIsPropagatedToLayout() { + PanelTemplateRecord t = new PanelTemplateRecord(Panel.Type.INVENTORY, + "my.custom.title", border(), null, + new boolean[]{true, true, true, true, false, false}); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(3, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals("my.custom.title", layout.panelTitle); + } + + @Test + void nullTemplateTitleFallsBackToDefaultTitleRef() { + // title is null in the template — should default to DEFAULT_TITLE_REF. + PanelTemplateRecord t = new PanelTemplateRecord(Panel.Type.INVENTORY, + null, border(), null, + new boolean[]{true, true, true, true, false, false}); + t.addButtonTemplate(0, 4, namedButton(Material.BOOK, "INFO", null)); + t.addButtonTemplate(3, 1, namedButton(Material.RED_STAINED_GLASS_PANE, "CANCEL", null)); + t.addButtonTemplate(3, 4, namedButton(Material.EXPERIENCE_BOTTLE, "PREVIEW", null)); + t.addButtonTemplate(3, 7, namedButton(Material.LIME_STAINED_GLASS_PANE, "CONFIRM", null)); + + DonationPanelLayout layout = DonationPanelLayout.fromTemplate(t); + + assertEquals(DonationPanelLayout.DEFAULT_TITLE_REF, layout.panelTitle); + } + + // ---- YAML structure test (no MockBukkit needed — YamlConfiguration is pure SnakeYAML) ---- + + @Test + void shippedDonationPanelYmlUsesListForceShownAndHasAllFourButtons() { + File ymlFile = new File("src/main/resources/panels/donation_panel.yml"); + assertTrue(ymlFile.exists(), "donation_panel.yml must exist under src/main/resources/panels/"); + + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(ymlFile); + + // force-shown must be a list (consistent with top_panel.yml / detail_panel.yml) + assertTrue(cfg.isList("donation_panel.force-shown"), + "force-shown must be a list, e.g. [1,2,3,4], not a scalar integer"); + + List forcedRows = cfg.getIntegerList("donation_panel.force-shown"); + assertEquals(4, forcedRows.size(), + "donation_panel.yml should force exactly 4 rows"); + + // All four named buttons must be present in the content section + assertNotNull(cfg.getString("donation_panel.content.1.5.data.type"), + "INFO button must be at row 1 col 5"); + assertEquals("INFO", cfg.getString("donation_panel.content.1.5.data.type")); + + assertNotNull(cfg.getString("donation_panel.content.4.2.data.type"), + "CANCEL button must be at row 4 col 2"); + assertEquals("CANCEL", cfg.getString("donation_panel.content.4.2.data.type")); + + assertNotNull(cfg.getString("donation_panel.content.4.5.data.type"), + "PREVIEW button must be at row 4 col 5"); + assertEquals("PREVIEW", cfg.getString("donation_panel.content.4.5.data.type")); + + assertNotNull(cfg.getString("donation_panel.content.4.8.data.type"), + "CONFIRM button must be at row 4 col 8"); + assertEquals("CONFIRM", cfg.getString("donation_panel.content.4.8.data.type")); + + // Title must match the default translation key + assertEquals(DonationPanelLayout.DEFAULT_TITLE_REF, + cfg.getString("donation_panel.title")); + } +} diff --git a/src/test/java/world/bentobox/level/requests/LevelRequestHandlerTest.java b/src/test/java/world/bentobox/level/requests/LevelRequestHandlerTest.java index 07bd421..abded1b 100644 --- a/src/test/java/world/bentobox/level/requests/LevelRequestHandlerTest.java +++ b/src/test/java/world/bentobox/level/requests/LevelRequestHandlerTest.java @@ -21,7 +21,7 @@ /** * Tests for {@link LevelRequestHandler} */ -public class LevelRequestHandlerTest extends CommonTestSetup { +class LevelRequestHandlerTest extends CommonTestSetup { @Mock private LevelsManager manager; @@ -30,7 +30,7 @@ public class LevelRequestHandlerTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getManager()).thenReturn(manager); mockedBukkit.when(() -> org.bukkit.Bukkit.getWorld(any(String.class))).thenReturn(world); @@ -39,29 +39,29 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testNullMapReturnsZero() { + void testNullMapReturnsZero() { assertEquals(0L, handler.handle(null)); } @Test - public void testEmptyMapReturnsZero() { + void testEmptyMapReturnsZero() { assertEquals(0L, handler.handle(Collections.emptyMap())); } @Test - public void testMissingWorldNameReturnsZero() { + void testMissingWorldNameReturnsZero() { Map map = new HashMap<>(); map.put("player", UUID.randomUUID()); assertEquals(0L, handler.handle(map)); } @Test - public void testWorldNameWrongTypeReturnsZero() { + void testWorldNameWrongTypeReturnsZero() { Map map = new HashMap<>(); map.put("world-name", 42); map.put("player", UUID.randomUUID()); @@ -69,7 +69,7 @@ public void testWorldNameWrongTypeReturnsZero() { } @Test - public void testPlayerWrongTypeReturnsZero() { + void testPlayerWrongTypeReturnsZero() { Map map = new HashMap<>(); map.put("world-name", "BSkyBlock_world"); map.put("player", "not-a-uuid"); @@ -77,14 +77,14 @@ public void testPlayerWrongTypeReturnsZero() { } @Test - public void testMissingPlayerReturnsZero() { + void testMissingPlayerReturnsZero() { Map map = new HashMap<>(); map.put("world-name", "BSkyBlock_world"); assertEquals(0L, handler.handle(map)); } @Test - public void testWorldNotFoundReturnsZero() { + void testWorldNotFoundReturnsZero() { mockedBukkit.when(() -> org.bukkit.Bukkit.getWorld(any(String.class))).thenReturn(null); Map map = new HashMap<>(); map.put("world-name", "nonexistent_world"); @@ -93,7 +93,7 @@ public void testWorldNotFoundReturnsZero() { } @Test - public void testValidInputDelegatesToManager() { + void testValidInputDelegatesToManager() { UUID playerUUID = UUID.randomUUID(); when(manager.getIslandLevel(any(World.class), any(UUID.class))).thenReturn(42L); @@ -105,7 +105,7 @@ public void testValidInputDelegatesToManager() { } @Test - public void testHandlerLabel() { + void testHandlerLabel() { assertEquals("island-level", handler.getLabel()); } } diff --git a/src/test/java/world/bentobox/level/requests/TopTenRequestHandlerTest.java b/src/test/java/world/bentobox/level/requests/TopTenRequestHandlerTest.java index 9b52408..880c6f5 100644 --- a/src/test/java/world/bentobox/level/requests/TopTenRequestHandlerTest.java +++ b/src/test/java/world/bentobox/level/requests/TopTenRequestHandlerTest.java @@ -23,7 +23,7 @@ /** * Tests for {@link TopTenRequestHandler} */ -public class TopTenRequestHandlerTest extends CommonTestSetup { +class TopTenRequestHandlerTest extends CommonTestSetup { @Mock private LevelsManager manager; @@ -32,7 +32,7 @@ public class TopTenRequestHandlerTest extends CommonTestSetup { @Override @BeforeEach - public void setUp() throws Exception { + protected void setUp() throws Exception { super.setUp(); when(addon.getManager()).thenReturn(manager); mockedBukkit.when(() -> org.bukkit.Bukkit.getWorld(any(String.class))).thenReturn(world); @@ -41,26 +41,26 @@ public void setUp() throws Exception { @Override @AfterEach - public void tearDown() throws Exception { + protected void tearDown() throws Exception { super.tearDown(); } @Test - public void testNullMapReturnsEmptyMap() { + void testNullMapReturnsEmptyMap() { Object result = handler.handle(null); assertTrue(result instanceof Map); assertTrue(((Map) result).isEmpty()); } @Test - public void testEmptyMapReturnsEmptyMap() { + void testEmptyMapReturnsEmptyMap() { Object result = handler.handle(Collections.emptyMap()); assertTrue(result instanceof Map); assertTrue(((Map) result).isEmpty()); } @Test - public void testMissingWorldNameReturnsEmptyMap() { + void testMissingWorldNameReturnsEmptyMap() { Map map = new HashMap<>(); Object result = handler.handle(map); assertTrue(result instanceof Map); @@ -68,7 +68,7 @@ public void testMissingWorldNameReturnsEmptyMap() { } @Test - public void testWorldNameWrongTypeReturnsEmptyMap() { + void testWorldNameWrongTypeReturnsEmptyMap() { Map map = new HashMap<>(); map.put("world-name", 123); Object result = handler.handle(map); @@ -77,7 +77,7 @@ public void testWorldNameWrongTypeReturnsEmptyMap() { } @Test - public void testWorldNotFoundReturnsEmptyMap() { + void testWorldNotFoundReturnsEmptyMap() { mockedBukkit.when(() -> org.bukkit.Bukkit.getWorld(any(String.class))).thenReturn(null); Map map = new HashMap<>(); map.put("world-name", "nonexistent_world"); @@ -87,7 +87,7 @@ public void testWorldNotFoundReturnsEmptyMap() { } @Test - public void testValidInputDelegatesToManager() { + void testValidInputDelegatesToManager() { LinkedHashMap topTen = new LinkedHashMap<>(); topTen.put("island-uuid-1", 500L); topTen.put("island-uuid-2", 400L); @@ -101,7 +101,7 @@ public void testValidInputDelegatesToManager() { } @Test - public void testHandlerLabel() { + void testHandlerLabel() { assertEquals("top-ten-level", handler.getLabel()); } } diff --git a/src/test/java/world/bentobox/level/util/CachedDataTest.java b/src/test/java/world/bentobox/level/util/CachedDataTest.java index 4b8c140..a41da6f 100644 --- a/src/test/java/world/bentobox/level/util/CachedDataTest.java +++ b/src/test/java/world/bentobox/level/util/CachedDataTest.java @@ -13,14 +13,14 @@ /** * Tests for {@link CachedData} */ -public class CachedDataTest { +class CachedDataTest { private Map initialMap; private Instant initialTime; private CachedData cachedData; @BeforeEach - public void setUp() { + void setUp() { initialMap = new HashMap<>(); initialMap.put("player1", 100L); initialMap.put("player2", 200L); @@ -29,25 +29,25 @@ public void setUp() { } @Test - public void testConstructorStoresMap() { + void testConstructorStoresMap() { assertNotNull(cachedData.getCachedMap()); assertEquals(initialMap, cachedData.getCachedMap()); } @Test - public void testConstructorStoresInstant() { + void testConstructorStoresInstant() { assertNotNull(cachedData.getLastUpdated()); assertEquals(initialTime, cachedData.getLastUpdated()); } @Test - public void testGetCachedMapReturnsCorrectEntries() { + void testGetCachedMapReturnsCorrectEntries() { assertEquals(100L, cachedData.getCachedMap().get("player1")); assertEquals(200L, cachedData.getCachedMap().get("player2")); } @Test - public void testUpdateCacheReplacesMap() { + void testUpdateCacheReplacesMap() { Map newMap = new HashMap<>(); newMap.put("player3", 300L); Instant newTime = Instant.now().plusSeconds(60); @@ -59,7 +59,7 @@ public void testUpdateCacheReplacesMap() { } @Test - public void testUpdateCacheReplacesInstant() { + void testUpdateCacheReplacesInstant() { Instant newTime = Instant.now().plusSeconds(120); cachedData.updateCache(new HashMap<>(), newTime); @@ -67,7 +67,7 @@ public void testUpdateCacheReplacesInstant() { } @Test - public void testUpdateCacheOldDataGone() { + void testUpdateCacheOldDataGone() { cachedData.updateCache(new HashMap<>(), Instant.now()); assertEquals(0, cachedData.getCachedMap().size()); } diff --git a/src/test/java/world/bentobox/level/util/UtilsTest.java b/src/test/java/world/bentobox/level/util/UtilsTest.java index c71f49e..0b8c7fe 100644 --- a/src/test/java/world/bentobox/level/util/UtilsTest.java +++ b/src/test/java/world/bentobox/level/util/UtilsTest.java @@ -17,12 +17,12 @@ /** * Tests for {@link Utils} */ -public class UtilsTest { +class UtilsTest { private User user; @BeforeEach - public void setUp() { + void setUp() { user = mock(User.class); when(user.isPlayer()).thenReturn(true); } @@ -30,37 +30,37 @@ public void setUp() { // --- getNextValue --- @Test - public void testGetNextValueMidArray() { + void testGetNextValueMidArray() { String[] values = {"A", "B", "C"}; assertEquals("B", Utils.getNextValue(values, "A")); } @Test - public void testGetNextValueLastWrapsToFirst() { + void testGetNextValueLastWrapsToFirst() { String[] values = {"A", "B", "C"}; assertEquals("A", Utils.getNextValue(values, "C")); } @Test - public void testGetNextValueMiddleElement() { + void testGetNextValueMiddleElement() { String[] values = {"A", "B", "C"}; assertEquals("C", Utils.getNextValue(values, "B")); } @Test - public void testGetNextValueNotFoundReturnsCurrent() { + void testGetNextValueNotFoundReturnsCurrent() { String[] values = {"A", "B", "C"}; assertEquals("Z", Utils.getNextValue(values, "Z")); } @Test - public void testGetNextValueSingleElement() { + void testGetNextValueSingleElement() { String[] values = {"A"}; assertEquals("A", Utils.getNextValue(values, "A")); } @Test - public void testGetNextValueWithEnums() { + void testGetNextValueWithEnums() { TestEnum[] values = TestEnum.values(); assertEquals(TestEnum.TWO, Utils.getNextValue(values, TestEnum.ONE)); assertEquals(TestEnum.ONE, Utils.getNextValue(values, TestEnum.THREE)); @@ -69,37 +69,37 @@ public void testGetNextValueWithEnums() { // --- getPreviousValue --- @Test - public void testGetPreviousValueMidArray() { + void testGetPreviousValueMidArray() { String[] values = {"A", "B", "C"}; assertEquals("A", Utils.getPreviousValue(values, "B")); } @Test - public void testGetPreviousValueFirstWrapsToLast() { + void testGetPreviousValueFirstWrapsToLast() { String[] values = {"A", "B", "C"}; assertEquals("C", Utils.getPreviousValue(values, "A")); } @Test - public void testGetPreviousValueLastElement() { + void testGetPreviousValueLastElement() { String[] values = {"A", "B", "C"}; assertEquals("B", Utils.getPreviousValue(values, "C")); } @Test - public void testGetPreviousValueNotFoundReturnsCurrent() { + void testGetPreviousValueNotFoundReturnsCurrent() { String[] values = {"A", "B", "C"}; assertEquals("Z", Utils.getPreviousValue(values, "Z")); } @Test - public void testGetPreviousValueSingleElement() { + void testGetPreviousValueSingleElement() { String[] values = {"A"}; assertEquals("A", Utils.getPreviousValue(values, "A")); } @Test - public void testGetPreviousValueWithEnums() { + void testGetPreviousValueWithEnums() { TestEnum[] values = TestEnum.values(); assertEquals(TestEnum.THREE, Utils.getPreviousValue(values, TestEnum.ONE)); assertEquals(TestEnum.TWO, Utils.getPreviousValue(values, TestEnum.THREE)); @@ -108,7 +108,7 @@ public void testGetPreviousValueWithEnums() { // --- getPermissionValue --- @Test - public void testGetPermissionValueReturnsMatchingSuffix() { + void testGetPermissionValueReturnsMatchingSuffix() { PermissionAttachmentInfo perm = mock(PermissionAttachmentInfo.class); when(perm.getPermission()).thenReturn("island.level.5"); when(user.getEffectivePermissions()).thenReturn(Set.of(perm)); @@ -118,7 +118,7 @@ public void testGetPermissionValueReturnsMatchingSuffix() { } @Test - public void testGetPermissionValueSkipsWildcard() { + void testGetPermissionValueSkipsWildcard() { PermissionAttachmentInfo wildcard = mock(PermissionAttachmentInfo.class); when(wildcard.getPermission()).thenReturn("island.level.*"); when(user.getEffectivePermissions()).thenReturn(Set.of(wildcard)); @@ -128,7 +128,7 @@ public void testGetPermissionValueSkipsWildcard() { } @Test - public void testGetPermissionValueNoMatchReturnsDefault() { + void testGetPermissionValueNoMatchReturnsDefault() { when(user.getEffectivePermissions()).thenReturn(Set.of()); String result = Utils.getPermissionValue(user, "island.level", "default"); @@ -136,7 +136,7 @@ public void testGetPermissionValueNoMatchReturnsDefault() { } @Test - public void testGetPermissionValueNotPlayerReturnsDefault() { + void testGetPermissionValueNotPlayerReturnsDefault() { when(user.isPlayer()).thenReturn(false); String result = Utils.getPermissionValue(user, "island.level", "default"); @@ -144,7 +144,7 @@ public void testGetPermissionValueNotPlayerReturnsDefault() { } @Test - public void testGetPermissionValueStripsTrailingDot() { + void testGetPermissionValueStripsTrailingDot() { PermissionAttachmentInfo perm = mock(PermissionAttachmentInfo.class); when(perm.getPermission()).thenReturn("island.level.10"); // Pass with trailing dot - method should strip it @@ -155,7 +155,7 @@ public void testGetPermissionValueStripsTrailingDot() { } @Test - public void testGetPermissionValuePrefixNotMatchingOtherPerms() { + void testGetPermissionValuePrefixNotMatchingOtherPerms() { PermissionAttachmentInfo perm = mock(PermissionAttachmentInfo.class); when(perm.getPermission()).thenReturn("island.other.5"); when(user.getEffectivePermissions()).thenReturn(Set.of(perm));