diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java index af72379e0..7a45f8535 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/Category.java @@ -101,6 +101,13 @@ public class Category implements Keyed { * the {@link SlimefunItem} that should be added to this {@link Category} */ public void add(SlimefunItem item) { + Validate.notNull(item, "Cannot add null Items to a Category!"); + + if (items.contains(item)) { + // Ignore duplicate entries + return; + } + items.add(item); } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/mocks/SlimefunMocks.java b/src/test/java/io/github/thebusybiscuit/slimefun4/mocks/SlimefunMocks.java index a1ecbb03e..90ce8e604 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/mocks/SlimefunMocks.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/mocks/SlimefunMocks.java @@ -7,6 +7,7 @@ import org.bukkit.NamespacedKey; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; import org.mockito.Mockito; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; @@ -17,14 +18,8 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; public final class SlimefunMocks { - private static final Category category = new Category(new NamespacedKey(SlimefunPlugin.instance, "test"), new CustomItem(Material.EMERALD, "&4Test Category")); - private SlimefunMocks() {} - public static Category getCategory() { - return category; - } - public static Inventory mockInventory(InventoryType type, ItemStack... contents) { Inventory inv = Mockito.mock(Inventory.class); @@ -34,11 +29,14 @@ public final class SlimefunMocks { return inv; } - public static SlimefunItem mockSlimefunItem(String id, ItemStack item) { + public static SlimefunItem mockSlimefunItem(Plugin plugin, String id, ItemStack item) { + Category category = new Category(new NamespacedKey(plugin, "test"), new CustomItem(Material.EMERALD, "&4Test Category")); + return new MockSlimefunItem(category, item, id); } - public static VanillaItem mockVanillaItem(Material type, boolean enabled) { + public static VanillaItem mockVanillaItem(Plugin plugin, Material type, boolean enabled) { + Category category = new Category(new NamespacedKey(plugin, "test"), new CustomItem(Material.EMERALD, "&4Test Category")); VanillaItem item = new VanillaItem(category, new ItemStack(type), type.name(), null, new ItemStack[9]); SlimefunPlugin.getItemCfg().setValue(type.name() + ".enabled", enabled); return item; diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestCategories.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestCategories.java index 0c8a013c8..8c50c9bdf 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestCategories.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestCategories.java @@ -43,18 +43,31 @@ public class TestCategories { @Test public void testCategoryGetters() { - Category category = SlimefunMocks.getCategory(); + Category category = new Category(new NamespacedKey(plugin, "getter_test"), new CustomItem(Material.DIAMOND_AXE, "&6Testing")); Assertions.assertEquals(3, category.getTier()); - Assertions.assertEquals(new NamespacedKey(SlimefunPlugin.instance, "test"), category.getKey()); - Assertions.assertEquals("Test Category", category.getUnlocalizedName()); + Assertions.assertEquals(new NamespacedKey(SlimefunPlugin.instance, "getter_test"), category.getKey()); + Assertions.assertEquals("Testing", category.getUnlocalizedName()); Assertions.assertEquals(0, category.getItems().size()); + } - SlimefunItem item = SlimefunMocks.mockSlimefunItem("CATEGORY_TEST_ITEM", new CustomItem(Material.BAMBOO, "&6Test Bamboo")); + @Test + public void testAddItem() { + Category category = new Category(new NamespacedKey(plugin, "items_test"), new CustomItem(Material.DIAMOND_AXE, "&6Testing")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "CATEGORY_ITEMS_TEST_ITEM", new CustomItem(Material.BAMBOO, "&6Test Bamboo")); + item.setCategory(category); item.register(plugin); item.load(); Assertions.assertEquals(1, category.getItems().size()); + + // Size must still be 1 since we disallow duplicates + item.setCategory(category); + item.setCategory(category); + Assertions.assertEquals(1, category.getItems().size()); + + Assertions.assertThrows(IllegalArgumentException.class, () -> category.add(null)); + Assertions.assertTrue(category.getItems().contains(item)); } @@ -66,7 +79,7 @@ public class TestCategories { // Empty Categories are also hidden Assertions.assertTrue(category.isHidden(player)); - SlimefunItem disabledItem = SlimefunMocks.mockSlimefunItem("DISABLED_CATEGORY_ITEM", new CustomItem(Material.BEETROOT, "&4Disabled")); + SlimefunItem disabledItem = SlimefunMocks.mockSlimefunItem(plugin, "DISABLED_CATEGORY_ITEM", new CustomItem(Material.BEETROOT, "&4Disabled")); SlimefunPlugin.getItemCfg().setValue("DISABLED_CATEGORY_ITEM.enabled", false); disabledItem.setCategory(category); disabledItem.register(plugin); @@ -75,7 +88,7 @@ public class TestCategories { // A disabled Item should also make the Category hide Assertions.assertTrue(category.isHidden(player)); - SlimefunItem item = SlimefunMocks.mockSlimefunItem("CATEGORY_HIDDEN_TEST", new CustomItem(Material.BAMBOO, "&6Test Bamboo")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "CATEGORY_HIDDEN_TEST", new CustomItem(Material.BAMBOO, "&6Test Bamboo")); item.setCategory(category); item.setHidden(true); item.register(plugin); @@ -90,25 +103,33 @@ public class TestCategories { @Test public void testContains() { - Category category = SlimefunMocks.getCategory(); - SlimefunItem item = SlimefunMocks.mockSlimefunItem("CATEGORY_TEST_ITEM_2", new CustomItem(Material.BOW, "&6Test Bow")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "CATEGORY_TEST_ITEM_2", new CustomItem(Material.BOW, "&6Test Bow")); item.register(plugin); item.load(); + Category category = item.getCategory(); + Assertions.assertTrue(category.contains(item)); Assertions.assertFalse(category.contains(null)); - Assertions.assertFalse(category.contains(SlimefunMocks.mockSlimefunItem("NULL", new ItemStack(Material.BEDROCK)))); + + // Unregistered Item + Assertions.assertFalse(category.contains(SlimefunMocks.mockSlimefunItem(plugin, "NULL", new ItemStack(Material.BEDROCK)))); } @Test public void testLockedCategories() { Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null)); - Category category = SlimefunMocks.getCategory(); - LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey()); + Category category = new Category(new NamespacedKey(plugin, "unlocked"), new CustomItem(Material.EMERALD, "&5I am SHERlocked")); + category.register(); + + Category unregistered = new Category(new NamespacedKey(plugin, "unregistered"), new CustomItem(Material.EMERALD, "&5I am unregistered")); + + LockedCategory locked = new LockedCategory(new NamespacedKey(plugin, "locked"), new CustomItem(Material.GOLD_NUGGET, "&6Locked Test"), category.getKey(), unregistered.getKey()); locked.register(); Assertions.assertTrue(locked.getParents().contains(category)); + Assertions.assertFalse(locked.getParents().contains(unregistered)); locked.removeParent(category); Assertions.assertFalse(locked.getParents().contains(category)); @@ -125,7 +146,7 @@ public class TestCategories { // Category with current Month Month month = LocalDate.now().getMonth(); SeasonalCategory category = new SeasonalCategory(new NamespacedKey(plugin, "seasonal"), month, 1, new CustomItem(Material.NETHER_STAR, "&cSeasonal Test")); - SlimefunItem item = SlimefunMocks.mockSlimefunItem("SEASONAL_ITEM", new CustomItem(Material.NETHER_STAR, "&dSeasonal Test Star")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "SEASONAL_ITEM", new CustomItem(Material.NETHER_STAR, "&dSeasonal Test Star")); item.setCategory(category); item.register(plugin); item.load(); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestItemHandlers.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestItemHandlers.java index 32d510b4c..afe7a5ba0 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestItemHandlers.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestItemHandlers.java @@ -33,7 +33,7 @@ public class TestItemHandlers { @Test public void testIllegalItemHandlers() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("ITEM_HANDLER_TEST", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "ITEM_HANDLER_TEST", new CustomItem(Material.DIAMOND, "&cTest")); item.register(plugin); Assertions.assertThrows(IllegalArgumentException.class, () -> item.addItemHandler()); @@ -43,7 +43,7 @@ public class TestItemHandlers { @Test public void testItemHandler() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("ITEM_HANDLER_TEST_2", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "ITEM_HANDLER_TEST_2", new CustomItem(Material.DIAMOND, "&cTest")); MockItemHandler handler = new MockItemHandler(); item.addItemHandler(handler); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestItemSettings.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestItemSettings.java index 3b0b221d1..9b39933df 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestItemSettings.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestItemSettings.java @@ -32,7 +32,7 @@ public class TestItemSettings { @Test public void testIllegalItemSettings() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("ITEM_SETTINGS_TEST", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "ITEM_SETTINGS_TEST", new CustomItem(Material.DIAMOND, "&cTest")); item.register(plugin); Assertions.assertThrows(IllegalArgumentException.class, () -> new ItemSetting<>("prematureInvocation", "Hello world").getValue()); @@ -43,7 +43,7 @@ public class TestItemSettings { @Test public void testAddItemSetting() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("ITEM_SETTINGS_TEST_2", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "ITEM_SETTINGS_TEST_2", new CustomItem(Material.DIAMOND, "&cTest")); ItemSetting setting = new ItemSetting<>("test", "Hello World"); Assertions.assertTrue(setting.isType(String.class)); @@ -65,7 +65,7 @@ public class TestItemSettings { @Test public void testUpdateItemSetting() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("ITEM_SETTINGS_TEST_3", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "ITEM_SETTINGS_TEST_3", new CustomItem(Material.DIAMOND, "&cTest")); ItemSetting setting = new ItemSetting<>("test", "Hello World"); item.addItemSetting(setting); @@ -81,7 +81,7 @@ public class TestItemSettings { @Test public void testAlreadyExistingItemSetting() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("ITEM_SETTINGS_TEST", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "ITEM_SETTINGS_TEST", new CustomItem(Material.DIAMOND, "&cTest")); item.addItemSetting(new ItemSetting<>("test", "Hello World")); Assertions.assertThrows(IllegalArgumentException.class, () -> item.addItemSetting(new ItemSetting<>("test", "Hello World"))); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestSlimefunItemRegistration.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestSlimefunItemRegistration.java index 4d8173246..9d6713a16 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestSlimefunItemRegistration.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/items/TestSlimefunItemRegistration.java @@ -39,7 +39,7 @@ public class TestSlimefunItemRegistration { @Test public void testSuccessfulRegistration() { String id = "TEST_ITEM"; - SlimefunItem item = SlimefunMocks.mockSlimefunItem(id, new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, id, new CustomItem(Material.DIAMOND, "&cTest")); Assertions.assertEquals(ItemState.UNREGISTERED, item.getState()); @@ -53,7 +53,7 @@ public class TestSlimefunItemRegistration { @Test public void testDisabledItem() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("DISABLED_ITEM", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "DISABLED_ITEM", new CustomItem(Material.DIAMOND, "&cTest")); SlimefunPlugin.getItemCfg().setValue("DISABLED_ITEM.enabled", false); item.register(plugin); @@ -63,7 +63,7 @@ public class TestSlimefunItemRegistration { @Test public void testWikiPages() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("WIKI_ITEM", new CustomItem(Material.BOOK, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "WIKI_ITEM", new CustomItem(Material.BOOK, "&cTest")); item.register(plugin); Assertions.assertFalse(item.getWikipage().isPresent()); @@ -81,7 +81,7 @@ public class TestSlimefunItemRegistration { @Disabled("This Test provokes a ClassNotFoundException") @Test public void testGetItemName() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("ITEM_NAME_TEST", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "ITEM_NAME_TEST", new CustomItem(Material.DIAMOND, "&cTest")); item.register(plugin); Assertions.assertEquals(ChatColor.RED + "Test", item.getItemName()); @@ -89,7 +89,7 @@ public class TestSlimefunItemRegistration { @Test public void testVanillaItemFallback() { - VanillaItem item = SlimefunMocks.mockVanillaItem(Material.ACACIA_SIGN, false); + VanillaItem item = SlimefunMocks.mockVanillaItem(plugin, Material.ACACIA_SIGN, false); item.register(plugin); Assertions.assertTrue(item.isUseableInWorkbench()); @@ -99,10 +99,10 @@ public class TestSlimefunItemRegistration { @Test public void testIdConflict() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("DUPLICATE_ID", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "DUPLICATE_ID", new CustomItem(Material.DIAMOND, "&cTest")); item.register(plugin); - SlimefunItem item2 = SlimefunMocks.mockSlimefunItem("DUPLICATE_ID", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item2 = SlimefunMocks.mockSlimefunItem(plugin, "DUPLICATE_ID", new CustomItem(Material.DIAMOND, "&cTest")); item2.register(plugin); Assertions.assertEquals(ItemState.ENABLED, item.getState()); @@ -111,7 +111,7 @@ public class TestSlimefunItemRegistration { @Test public void testRecipeOutput() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("RECIPE_OUTPUT_TEST", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "RECIPE_OUTPUT_TEST", new CustomItem(Material.DIAMOND, "&cTest")); item.register(plugin); Assertions.assertEquals(item.getItem(), item.getRecipeOutput()); @@ -127,7 +127,7 @@ public class TestSlimefunItemRegistration { @Test public void testIsItem() { CustomItem item = new CustomItem(Material.BEACON, "&cItem Test"); - SlimefunItem sfItem = SlimefunMocks.mockSlimefunItem("IS_ITEM_TEST", item); + SlimefunItem sfItem = SlimefunMocks.mockSlimefunItem(plugin, "IS_ITEM_TEST", item); sfItem.register(plugin); Assertions.assertTrue(sfItem.isItem(sfItem.getItem())); @@ -143,14 +143,14 @@ public class TestSlimefunItemRegistration { @Test public void testCategoryRegistration() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("CATEGORY_TEST", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "CATEGORY_TEST", new CustomItem(Material.DIAMOND, "&cTest")); item.register(plugin); item.load(); // null should not be a valid argument Assertions.assertThrows(IllegalArgumentException.class, () -> item.setCategory(null)); - Category category = SlimefunMocks.getCategory(); + Category category = item.getCategory(); Category category2 = new Category(new NamespacedKey(plugin, "test2"), new CustomItem(Material.OBSIDIAN, "&6Test 2")); Assertions.assertTrue(category.contains(item)); @@ -165,12 +165,12 @@ public class TestSlimefunItemRegistration { @Test public void testHiddenItem() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("HIDDEN_TEST", new CustomItem(Material.DIAMOND, "&cTest")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "HIDDEN_TEST", new CustomItem(Material.DIAMOND, "&cTest")); item.setHidden(true); item.register(plugin); item.load(); - Category category = SlimefunMocks.getCategory(); + Category category = item.getCategory(); Assertions.assertTrue(item.isHidden()); Assertions.assertFalse(category.contains(item)); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestIronGolemListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestIronGolemListener.java index 693670d26..69bcfdfc5 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestIronGolemListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestIronGolemListener.java @@ -75,7 +75,7 @@ public class TestIronGolemListener { @Test public void testWithSlimefunIron() { - SlimefunItem slimefunItem = SlimefunMocks.mockSlimefunItem("SLIMEFUN_IRON", new CustomItem(Material.IRON_INGOT, "&cSlimefun Iron")); + SlimefunItem slimefunItem = SlimefunMocks.mockSlimefunItem(plugin, "SLIMEFUN_IRON", new CustomItem(Material.IRON_INGOT, "&cSlimefun Iron")); slimefunItem.register(plugin); // The Event should be cancelled, we do not wanna use Slimefun Items for this @@ -88,7 +88,7 @@ public class TestIronGolemListener { @Test public void testWithVanillaIron() { - VanillaItem item = SlimefunMocks.mockVanillaItem(Material.IRON_INGOT, true); + VanillaItem item = SlimefunMocks.mockVanillaItem(plugin, Material.IRON_INGOT, true); item.register(plugin); PlayerInteractEntityEvent event = callIronGolemEvent(EquipmentSlot.HAND, item.getItem()); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestVanillaMachinesListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestVanillaMachinesListener.java index 31392493c..3fc103439 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestVanillaMachinesListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/listeners/TestVanillaMachinesListener.java @@ -128,7 +128,7 @@ public class TestVanillaMachinesListener { @Test public void testGrindStoneWithSlimefunItem() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("ENCHANTED_MOCK_BOOK", new CustomItem(Material.ENCHANTED_BOOK, "&6Mock")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "ENCHANTED_MOCK_BOOK", new CustomItem(Material.ENCHANTED_BOOK, "&6Mock")); item.register(plugin); InventoryClickEvent event = mockGrindStoneEvent(item.getItem()); @@ -137,7 +137,7 @@ public class TestVanillaMachinesListener { @Test public void testGrindStoneWithVanillaItem() { - VanillaItem item = SlimefunMocks.mockVanillaItem(Material.ENCHANTED_BOOK, true); + VanillaItem item = SlimefunMocks.mockVanillaItem(plugin, Material.ENCHANTED_BOOK, true); item.register(plugin); InventoryClickEvent event = mockGrindStoneEvent(item.getItem()); @@ -158,7 +158,7 @@ public class TestVanillaMachinesListener { @Test public void testCraftEventWithSlimefunItem() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("MOCK_DIAMOND", new CustomItem(Material.DIAMOND, "&cMock Diamond")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "MOCK_DIAMOND", new CustomItem(Material.DIAMOND, "&cMock Diamond")); item.register(plugin); CraftItemEvent event = mockCraftingEvent(item.getItem()); @@ -167,7 +167,7 @@ public class TestVanillaMachinesListener { @Test public void testCraftEventWithChangingSlimefunItem() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("CHANGING_ITEM", new CustomItem(Material.DIAMOND, "&dChanging Diamond")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "CHANGING_ITEM", new CustomItem(Material.DIAMOND, "&dChanging Diamond")); item.register(plugin); item.setUseableInWorkbench(true); @@ -181,7 +181,7 @@ public class TestVanillaMachinesListener { @Test public void testCraftEventWithVanillaItem() { - VanillaItem item = SlimefunMocks.mockVanillaItem(Material.DIAMOND, true); + VanillaItem item = SlimefunMocks.mockVanillaItem(plugin, Material.DIAMOND, true); item.register(plugin); CraftItemEvent event = mockCraftingEvent(item.getItem()); @@ -196,7 +196,7 @@ public class TestVanillaMachinesListener { @Test public void testPreCraftEventWithSlimefunItem() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("MOCK_DIAMOND2", new CustomItem(Material.DIAMOND, "&cMock Diamond")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "MOCK_DIAMOND2", new CustomItem(Material.DIAMOND, "&cMock Diamond")); item.register(plugin); PrepareItemCraftEvent event = mockPreCraftingEvent(item.getItem()); @@ -205,13 +205,13 @@ public class TestVanillaMachinesListener { @Test public void testPreCraftEventWithVanillaItem() { - VanillaItem item = SlimefunMocks.mockVanillaItem(Material.GOLD_INGOT, true); + VanillaItem item = SlimefunMocks.mockVanillaItem(plugin, Material.GOLD_INGOT, true); item.register(plugin); PrepareItemCraftEvent event = mockPreCraftingEvent(item.getItem()); Assertions.assertNotNull(event.getInventory().getResult()); } - + @Test public void testAnvilWithoutSlimefunItems() { InventoryClickEvent event = mockAnvilEvent(new ItemStack(Material.IRON_SWORD)); @@ -220,7 +220,7 @@ public class TestVanillaMachinesListener { @Test public void testAnvilWithSlimefunItem() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("MOCKED_IRON_SWORD", new CustomItem(Material.IRON_SWORD, "&6Mock")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "MOCKED_IRON_SWORD", new CustomItem(Material.IRON_SWORD, "&6Mock")); item.register(plugin); InventoryClickEvent event = mockAnvilEvent(item.getItem()); @@ -229,13 +229,13 @@ public class TestVanillaMachinesListener { @Test public void testAnvilWithVanillaItem() { - VanillaItem item = SlimefunMocks.mockVanillaItem(Material.IRON_SWORD, true); + VanillaItem item = SlimefunMocks.mockVanillaItem(plugin, Material.IRON_SWORD, true); item.register(plugin); InventoryClickEvent event = mockAnvilEvent(item.getItem()); Assertions.assertEquals(Result.DEFAULT, event.getResult()); } - + @Test public void testBrewingWithoutSlimefunItems() { InventoryClickEvent event = mockBrewingEvent(new ItemStack(Material.BLAZE_POWDER)); @@ -244,7 +244,7 @@ public class TestVanillaMachinesListener { @Test public void testBrewingWithSlimefunItem() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("MOCK_POWDER", new CustomItem(Material.BLAZE_POWDER, "&6Mock")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "MOCK_POWDER", new CustomItem(Material.BLAZE_POWDER, "&6Mock")); item.register(plugin); InventoryClickEvent event = mockBrewingEvent(item.getItem()); @@ -253,7 +253,7 @@ public class TestVanillaMachinesListener { @Test public void testBrewingithVanillaItem() { - VanillaItem item = SlimefunMocks.mockVanillaItem(Material.BLAZE_POWDER, true); + VanillaItem item = SlimefunMocks.mockVanillaItem(plugin, Material.BLAZE_POWDER, true); item.register(plugin); InventoryClickEvent event = mockBrewingEvent(item.getItem()); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/multiblocks/TestMultiBlocks.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/multiblocks/TestMultiBlocks.java index 63c8129d8..d795f6cb7 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/multiblocks/TestMultiBlocks.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/multiblocks/TestMultiBlocks.java @@ -11,13 +11,17 @@ import be.seeseemelk.mockbukkit.MockBukkit; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.core.MultiBlock; import io.github.thebusybiscuit.slimefun4.mocks.SlimefunMocks; +import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; public class TestMultiBlocks { + private static SlimefunPlugin plugin; + @BeforeAll public static void load() { MockBukkit.mock(); + plugin = MockBukkit.load(SlimefunPlugin.class); } @AfterAll @@ -27,7 +31,7 @@ public class TestMultiBlocks { @Test public void testInvalidConstructors() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test")); Assertions.assertThrows(IllegalArgumentException.class, () -> new MultiBlock(null, null, null)); @@ -39,7 +43,7 @@ public class TestMultiBlocks { @Test public void testValidConstructor() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test")); MultiBlock multiblock = new MultiBlock(item, new Material[9], BlockFace.DOWN); Assertions.assertEquals(item, multiblock.getSlimefunItem()); @@ -49,7 +53,7 @@ public class TestMultiBlocks { @Test public void testSymmetry() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test")); MultiBlock multiblock = new MultiBlock(item, new Material[] { null, null, null, Material.DIAMOND_BLOCK, null, Material.DIAMOND_BLOCK, null, Material.DISPENSER, null }, BlockFace.DOWN); @@ -62,7 +66,7 @@ public class TestMultiBlocks { @Test public void testEquality() { - SlimefunItem item = SlimefunMocks.mockSlimefunItem("MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test")); MultiBlock multiblock = new MultiBlock(item, new Material[] { Material.BIRCH_WOOD, Material.BIRCH_WOOD, Material.BIRCH_WOOD, null, Material.CRAFTING_TABLE, null, Material.BIRCH_WOOD, Material.DISPENSER, Material.BIRCH_WOOD }, BlockFace.DOWN); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/researches/TestResearches.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/researches/TestResearches.java index 85bb442ee..1e1839449 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/researches/TestResearches.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/researches/TestResearches.java @@ -61,7 +61,7 @@ public class TestResearches { public void testResearchRegistration() { NamespacedKey key = new NamespacedKey(plugin, "testResearch"); Research research = new Research(key, 1, "Test", 100); - SlimefunItem item = SlimefunMocks.mockSlimefunItem("RESEARCH_TEST", new CustomItem(Material.TORCH, "&bResearch Test")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "RESEARCH_TEST", new CustomItem(Material.TORCH, "&bResearch Test")); research.addItems(item, null); research.register(); @@ -80,7 +80,7 @@ public class TestResearches { public void testDisabledResearch() { NamespacedKey key = new NamespacedKey(plugin, "disabledResearch"); Research research = new Research(key, 2, "Test", 100); - SlimefunItem item = SlimefunMocks.mockSlimefunItem("RESEARCH_TEST", new CustomItem(Material.TORCH, "&bResearch Test")); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "RESEARCH_TEST", new CustomItem(Material.TORCH, "&bResearch Test")); research.addItems(item); SlimefunPlugin.getRegistry().setResearchingEnabled(true); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/services/TextCustomTextureService.java b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/services/TextCustomTextureService.java index 20ad3dc22..6088f22e6 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/tests/services/TextCustomTextureService.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/tests/services/TextCustomTextureService.java @@ -38,7 +38,7 @@ public class TextCustomTextureService { Assertions.assertFalse(service.isActive()); Assertions.assertNull(service.getVersion()); - SlimefunItem item = SlimefunMocks.mockSlimefunItem("TEXTURE_TEST", new ItemStack(Material.LANTERN)); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "TEXTURE_TEST", new ItemStack(Material.LANTERN)); service.register(Arrays.asList(null, item, null), false); Assertions.assertThrows(IllegalArgumentException.class, () -> service.register(null, false)); @@ -53,7 +53,7 @@ public class TextCustomTextureService { @Test public void testSetTexture() throws NoSuchFieldException, IllegalAccessException { CustomTextureService service = new CustomTextureService(plugin); - SlimefunItem item = SlimefunMocks.mockSlimefunItem("TEXTURE_TEST", new ItemStack(Material.LANTERN)); + SlimefunItem item = SlimefunMocks.mockSlimefunItem(plugin, "TEXTURE_TEST", new ItemStack(Material.LANTERN)); String version = "Unit Test v1.0"; Config config = (Config) ReflectionUtils.getFieldValue(service, "config");