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 1c71fca13..5241dbe7b 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 @@ -34,7 +34,7 @@ class TestItemStackWrapper { @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); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(item); Assertions.assertEquals(item.getType(), wrapper.getType()); Assertions.assertEquals(item.hasItemMeta(), wrapper.hasItemMeta()); @@ -46,7 +46,7 @@ class TestItemStackWrapper { @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); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(item); Assertions.assertEquals(item.getType(), wrapper.getType()); Assertions.assertEquals(item.hasItemMeta(), wrapper.hasItemMeta()); @@ -58,7 +58,7 @@ class TestItemStackWrapper { @DisplayName("Test if an ItemStackWrapper is immutable") void testImmutability() { ItemStack item = new CustomItem(Material.LAVA_BUCKET, "&4SuperHot.exe", "", "&6Hello"); - ItemStackWrapper wrapper = new ItemStackWrapper(item); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(item); Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.setType(Material.BEDROCK)); Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.setAmount(3)); @@ -69,6 +69,20 @@ class TestItemStackWrapper { Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.equals(wrapper)); } + @Test + @DisplayName("Test if the ItemStackWrapper static method constructors are checking for nested wrapping properly") + void testWrapperChecking() { + ItemStack item = new CustomItem(Material.IRON_INGOT, "A Name", "line 1", "line2"); + ItemStackWrapper wrapper = ItemStackWrapper.ofItem(item); + ItemStackWrapper secondWrap = ItemStackWrapper.ofItem(wrapper); + // We want to check that the wrapper returned is of reference equality + Assertions.assertTrue(wrapper == secondWrap); + ItemStackWrapper forceSecondWrap = ItemStackWrapper.forceWrapItem(wrapper); + // Want to check that the wrapper returned is of different reference equality + Assertions.assertFalse(wrapper == forceSecondWrap); + assertWrapped(wrapper, forceSecondWrap); + } + @Test @DisplayName("Test wrapping an ItemStack Array") void testWrapArray() { @@ -80,19 +94,35 @@ class TestItemStackWrapper { for (int i = 0; i < items.length; i++) { assertWrapped(items[i], wrappers[i]); } + + ItemStackWrapper[] nestedWrap = ItemStackWrapper.wrapArray(wrappers); + + Assertions.assertEquals(wrappers.length, nestedWrap.length); + for (int i = 0; i < wrappers.length; i++) { + // We want to check that the wrapper returned is of reference equality + Assertions.assertTrue(wrappers[i] == nestedWrap[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); + 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)); } + + final List nestedWrappers = ItemStackWrapper.wrapList((List) wrappers); + + Assertions.assertEquals(wrappers.size(), nestedWrappers.size()); + for (int i = 0; i < items.size(); i++) { + // We want to check that the wrapper returned is of reference equality + Assertions.assertTrue(wrappers.get(i) == nestedWrappers.get(i)); + } } private void assertWrapped(ItemStack expected, ItemStack actual) {