diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java index e45936f88..92577900d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java @@ -42,7 +42,9 @@ public class BeeListener implements Listener { if (profile.hasFullProtectionAgainst(ProtectionType.BEES)) { for (ItemStack armor : p.getInventory().getArmorContents()) { - ItemUtils.damageItem(armor, 1, false); + if (armor != null) { + ItemUtils.damageItem(armor, 1, false); + } } e.setDamage(0D); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestBackpackCommand.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestBackpackCommand.java index de4559d66..67eb67e5a 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestBackpackCommand.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestBackpackCommand.java @@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -22,7 +23,7 @@ import io.github.thebusybiscuit.slimefun4.testing.TestUtilities; import io.github.thebusybiscuit.slimefun4.utils.PatternUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -public class TestBackpackCommand { +class TestBackpackCommand { private static ServerMock server; @@ -52,7 +53,8 @@ public class TestBackpackCommand { } @Test - public void testValidBackpack() throws InterruptedException { + @DisplayName("Test /sf backpack giving a restored backpack") + void testValidBackpack() throws InterruptedException { Player player = server.addPlayer(); player.setOp(true); PlayerProfile profile = TestUtilities.awaitProfile(player); @@ -64,8 +66,9 @@ public class TestBackpackCommand { } @ParameterizedTest - @ValueSource(strings = { "ABC", "-100", "123456789" }) - public void testNonExistantBackpacks(String id) throws InterruptedException { + @DisplayName("Test /sf backpack with invalid id parameters") + @ValueSource(strings = { "", " ", "ABC", "-100", "123456789" }) + void testNonExistentBackpacks(String id) throws InterruptedException { Player player = server.addPlayer(); player.setOp(true); TestUtilities.awaitProfile(player); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestDebugFishCommand.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestDebugFishCommand.java index 81360c0d2..a7497a3e7 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestDebugFishCommand.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestDebugFishCommand.java @@ -4,6 +4,7 @@ import org.bukkit.entity.Player; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -13,7 +14,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -public class TestDebugFishCommand { +class TestDebugFishCommand { private static ServerMock server; @@ -30,7 +31,8 @@ public class TestDebugFishCommand { @ParameterizedTest @ValueSource(booleans = { true, false }) - public void testCommand(boolean op) { + @DisplayName("Test if Debug Fish is given on /sf debug_fish") + void testCommand(boolean op) { Player player = server.addPlayer(); player.setOp(op); server.execute("slimefun", player, "debug_fish").assertSucceeded(); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java index 1976f6f2a..663d1e1bc 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/commands/TestGuideCommand.java @@ -5,6 +5,7 @@ import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -15,7 +16,7 @@ import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; -public class TestGuideCommand { +class TestGuideCommand { private static ServerMock server; @@ -31,8 +32,9 @@ public class TestGuideCommand { } @ParameterizedTest + @DisplayName("Test if Slimefun Guide is given on /sf guide") @ValueSource(booleans = { true, false }) - public void testCommand(boolean op) { + void testCommand(boolean op) { Player player = server.addPlayer(); player.setOp(op); server.execute("slimefun", player, "guide").assertSucceeded(); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java index 6ae0170ac..6d56a54e6 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestBookSlimefunGuide.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.guide; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; @@ -10,7 +11,7 @@ import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.guide.BookSlimefunGuide; -public class TestBookSlimefunGuide { +class TestBookSlimefunGuide { @BeforeAll public static void load() { @@ -24,7 +25,8 @@ public class TestBookSlimefunGuide { } @Test - public void testBasicGetters() { + @DisplayName("Test Getters for Chest Slimefun Guide") + void testBasicGetters() { BookSlimefunGuide guide = new BookSlimefunGuide(); Assertions.assertEquals(SlimefunGuideLayout.BOOK, guide.getLayout()); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java index 260ed9bc1..5880e650f 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/guide/TestChestSlimefunGuide.java @@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.guide; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; @@ -10,7 +11,7 @@ import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide; -public class TestChestSlimefunGuide { +class TestChestSlimefunGuide { @BeforeAll public static void load() { @@ -24,7 +25,8 @@ public class TestChestSlimefunGuide { } @Test - public void testBasicGetters() { + @DisplayName("Test Getters for Chest Slimefun Guide") + void testBasicGetters() { ChestSlimefunGuide guide = new ChestSlimefunGuide(false); Assertions.assertEquals(SlimefunGuideLayout.CHEST, guide.getLayout()); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/implementations/backpacks/TestEnderBackpack.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/implementations/backpacks/TestEnderBackpack.java index 5684b59b9..12fab7fa3 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/implementations/backpacks/TestEnderBackpack.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/items/implementations/backpacks/TestEnderBackpack.java @@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; @@ -17,7 +18,7 @@ import io.github.thebusybiscuit.slimefun4.testing.interfaces.SlimefunItemTest; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -public class TestEnderBackpack implements SlimefunItemTest { +class TestEnderBackpack implements SlimefunItemTest { private static ServerMock server; private static SlimefunPlugin plugin; @@ -42,7 +43,8 @@ public class TestEnderBackpack implements SlimefunItemTest { } @Test - public void testRightClickBehaviour() { + @DisplayName("Test Ender Backpack opening Enderchest") + void testRightClickBehaviour() { Player player = server.addPlayer(); EnderBackpack backpack = registerSlimefunItem(plugin, "TEST_ENDER_BACKPACK"); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/MockBeeProtectionSuit.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/MockBeeProtectionSuit.java new file mode 100644 index 000000000..43fdc850a --- /dev/null +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/MockBeeProtectionSuit.java @@ -0,0 +1,35 @@ +package io.github.thebusybiscuit.slimefun4.testing.tests.listeners; + +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; + +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectiveArmor; +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +class MockBeeProtectionSuit extends SlimefunArmorPiece implements ProtectiveArmor { + + public MockBeeProtectionSuit(Category category, SlimefunItemStack item) { + super(category, item, RecipeType.NULL, new ItemStack[9], new PotionEffect[0]); + } + + @Override + public ProtectionType[] getProtectionTypes() { + return new ProtectionType[] { ProtectionType.BEES }; + } + + @Override + public boolean isFullSetRequired() { + return false; + } + + @Override + public NamespacedKey getArmorSetId() { + return new NamespacedKey(getAddon().getJavaPlugin(), "mock_bees"); + } + +} diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestBeeListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestBeeListener.java new file mode 100644 index 000000000..c154d93a8 --- /dev/null +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestBeeListener.java @@ -0,0 +1,75 @@ +package io.github.thebusybiscuit.slimefun4.testing.tests.listeners; + +import org.bukkit.Material; +import org.bukkit.entity.Bee; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.Mockito; + +import be.seeseemelk.mockbukkit.MockBukkit; +import be.seeseemelk.mockbukkit.ServerMock; +import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.BeeListener; +import io.github.thebusybiscuit.slimefun4.testing.TestUtilities; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +class TestBeeListener { + + private static ServerMock server; + private static SlimefunPlugin plugin; + private static BeeListener listener; + + @BeforeAll + public static void load() { + server = MockBukkit.mock(); + plugin = MockBukkit.load(SlimefunPlugin.class); + listener = new BeeListener(plugin); + } + + @AfterAll + public static void unload() { + MockBukkit.unmock(); + } + + @ParameterizedTest + @DisplayName("Test Bee damage protection") + @ValueSource(booleans = { true, false }) + void testBeeDamage(boolean hasArmor) throws InterruptedException { + Player player = server.addPlayer(); + PlayerProfile profile = TestUtilities.awaitProfile(player); + + if (hasArmor) { + Category category = TestUtilities.getCategory(plugin, "bee_suit_test"); + SlimefunItemStack chestplate = new SlimefunItemStack("MOCK_BEE_SUIT", Material.LEATHER_CHESTPLATE, "&cBee Suit Prototype"); + MockBeeProtectionSuit armor = new MockBeeProtectionSuit(category, chestplate); + armor.register(plugin); + + player.getInventory().setChestplate(chestplate.clone()); + // Force update the cached armor + profile.getArmor()[1].update(chestplate, armor); + } + + double damage = 7.5; + + Bee bee = Mockito.mock(Bee.class); + EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(bee, player, DamageCause.ENTITY_ATTACK, damage); + listener.onDamage(event); + + if (hasArmor) { + Assertions.assertEquals(0, event.getDamage()); + } + else { + Assertions.assertEquals(damage, event.getDamage()); + } + } + +} diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestCoolerListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestCoolerListener.java index c594dfb3c..e3dd6b8e7 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestCoolerListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestCoolerListener.java @@ -11,6 +11,7 @@ import org.bukkit.potion.PotionEffectType; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; @@ -28,7 +29,7 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; -public class TestCoolerListener { +class TestCoolerListener { private static ServerMock server; private static CoolerListener listener; @@ -59,14 +60,16 @@ public class TestCoolerListener { } @Test - public void testOnlyJuiceAllowance() { + @DisplayName("Test if Coolers only allow juices") + void testOnlyJuiceAllowance() { Assertions.assertFalse(cooler.isItemAllowed(new ItemStack(Material.DIAMOND), null)); Assertions.assertFalse(cooler.isItemAllowed(cooler.getItem(), cooler)); Assertions.assertTrue(cooler.isItemAllowed(juice.getItem(), juice)); } @Test - public void testCoolerUsage() throws InterruptedException { + @DisplayName("Test if Coolers consume Juices when hunger gets low") + void testCoolerUsage() throws InterruptedException { Player player = server.addPlayer(); PlayerProfile profile = TestUtilities.awaitProfile(player); PlayerBackpack backpack = profile.createBackpack(cooler.getSize()); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestFireworksListener.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestFireworksListener.java index 849416af7..bc5f4709d 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestFireworksListener.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/listeners/TestFireworksListener.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.meta.FireworkMeta; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -19,7 +20,7 @@ import be.seeseemelk.mockbukkit.inventory.meta.FireworkMetaMock; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.listeners.FireworksListener; -public class TestFireworksListener { +class TestFireworksListener { private static ServerMock server; @@ -36,7 +37,8 @@ public class TestFireworksListener { } @Test - public void testFireworkDamage() { + @DisplayName("Test if Fireworks from Research cause no damage") + void testFireworkDamage() { Player player = server.addPlayer(); Firework firework = Mockito.mock(Firework.class); FireworkMeta meta = new FireworkMetaMock(); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/services/TextCustomTextureService.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/services/TextCustomTextureService.java index 16daca7d5..44801d46f 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/services/TextCustomTextureService.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/services/TextCustomTextureService.java @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; @@ -16,7 +17,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.testing.TestUtilities; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -public class TextCustomTextureService { +class TextCustomTextureService { private static SlimefunPlugin plugin; @@ -32,7 +33,8 @@ public class TextCustomTextureService { } @Test - public void testInitialization() { + @DisplayName("Test creating a new Custom Texture Service") + void testInitialization() { Config config = new Config("plugins/temporary"); CustomTextureService service = new CustomTextureService(config); Assertions.assertFalse(service.isActive()); @@ -51,7 +53,8 @@ public class TextCustomTextureService { } @Test - public void testSetTexture() { + @DisplayName("Test applying a custom item model") + void testSetTexture() { Config config = new Config("plugins/temporary"); CustomTextureService service = new CustomTextureService(config); SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "TEXTURE_TEST", new ItemStack(Material.LANTERN)); diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestHeadTextures.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestHeadTextures.java index 7952d410f..c320da673 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestHeadTextures.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestHeadTextures.java @@ -4,14 +4,16 @@ import java.util.HashSet; import java.util.Set; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; -public class TestHeadTextures { +class TestHeadTextures { @Test - public void testForDuplicates() { + @DisplayName("Test if the HeadTexture enum contains any duplicates") + void testForDuplicates() { Set textures = new HashSet<>(); for (HeadTexture head : HeadTexture.values()) { diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestItemStackWrapper.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestItemStackWrapper.java index 0e85707a8..e58748a39 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestItemStackWrapper.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestItemStackWrapper.java @@ -1,10 +1,14 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.utils; +import java.util.Arrays; +import java.util.List; + import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import be.seeseemelk.mockbukkit.MockBukkit; @@ -13,7 +17,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper; -public class TestItemStackWrapper { +class TestItemStackWrapper { @BeforeAll public static void load() { @@ -27,7 +31,8 @@ public class TestItemStackWrapper { } @Test - public void testEquality() { + @DisplayName("Test if an ItemStackWrappers can be compared properly (With ItemMeta)") + void testEqualityWithItemMeta() { ItemStack item = new CustomItem(Material.LAVA_BUCKET, "&4SuperHot.exe", "", "&6Hello"); ItemStackWrapper wrapper = new ItemStackWrapper(item); @@ -38,7 +43,20 @@ public class TestItemStackWrapper { } @Test - public void testImmutability() { + @DisplayName("Test if an ItemStackWrappers can be compared properly (No ItemMeta)") + void testEqualityWithoutItemMeta() { + ItemStack item = new ItemStack(Material.DIAMOND_AXE); + ItemStackWrapper wrapper = new ItemStackWrapper(item); + + Assertions.assertEquals(item.getType(), wrapper.getType()); + Assertions.assertEquals(item.hasItemMeta(), wrapper.hasItemMeta()); + Assertions.assertEquals(item.getItemMeta(), wrapper.getItemMeta()); + Assertions.assertTrue(SlimefunUtils.isItemSimilar(wrapper, item, true)); + } + + @Test + @DisplayName("Test if an ItemStackWrapper is immutable") + void testImmutability() { ItemStack item = new CustomItem(Material.LAVA_BUCKET, "&4SuperHot.exe", "", "&6Hello"); ItemStackWrapper wrapper = new ItemStackWrapper(item); @@ -51,4 +69,39 @@ public class TestItemStackWrapper { Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.equals(wrapper)); } + @Test + @DisplayName("Test wrapping an ItemStack Array") + void testWrapArray() { + ItemStack[] items = { new ItemStack(Material.DIAMOND), null, new ItemStack(Material.EMERALD), new CustomItem(Material.REDSTONE, "&4Firey thing", "with lore :o") }; + ItemStackWrapper[] wrappers = ItemStackWrapper.wrapArray(items); + + Assertions.assertEquals(items.length, wrappers.length); + + for (int i = 0; i < items.length; i++) { + assertWrapped(items[i], wrappers[i]); + } + } + + @Test + @DisplayName("Test wrapping an ItemStack List") + void testWrapList() { + List items = Arrays.asList(new ItemStack(Material.DIAMOND), null, new ItemStack(Material.EMERALD), new CustomItem(Material.REDSTONE, "&4Firey thing", "with lore :o")); + List wrappers = ItemStackWrapper.wrapList(items); + + Assertions.assertEquals(items.size(), wrappers.size()); + + for (int i = 0; i < items.size(); i++) { + assertWrapped(items.get(i), wrappers.get(i)); + } + } + + private void assertWrapped(ItemStack expected, ItemStack actual) { + if (expected == null) { + Assertions.assertNull(actual); + } + else { + Assertions.assertTrue(actual instanceof ItemStackWrapper); + Assertions.assertTrue(SlimefunUtils.isItemSimilar(actual, expected, true)); + } + } } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestWikiResource.java b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestWikiResource.java index 2b4202be2..2ad9293ce 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestWikiResource.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/testing/tests/utils/TestWikiResource.java @@ -8,15 +8,17 @@ import java.util.Map; import java.util.regex.Pattern; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -public class TestWikiResource { +class TestWikiResource { @Test - public void testWikiJson() throws IOException { + @DisplayName("Test wiki.json file format") + void testWikiJson() throws IOException { JsonParser parser = new JsonParser(); Pattern pattern = Pattern.compile("[A-Z_0-9]+");