1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Added ItemStackWrapper Unit Tests

This commit is contained in:
TheBusyBiscuit 2020-05-10 15:34:04 +02:00
parent fe499a357e
commit 990b717339
2 changed files with 50 additions and 2 deletions

View File

@ -21,7 +21,7 @@ public final class ItemStackWrapper extends ItemStack {
private ItemMeta meta;
public ItemStackWrapper(ItemStack item) {
super(item.getType(), item.getAmount());
super(item.getType());
meta = item.getItemMeta();
}
@ -41,7 +41,7 @@ public final class ItemStackWrapper extends ItemStack {
@Override
public boolean equals(Object obj) {
throw new UnsupportedOperationException("ItemStackWrapper do not allow .equals()");
throw new UnsupportedOperationException("ItemStackWrappers do not allow .equals()");
}
@Override

View File

@ -0,0 +1,48 @@
package io.github.thebusybiscuit.slimefun4.tests.utils;
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.Test;
import be.seeseemelk.mockbukkit.MockBukkit;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper;
public class TestItemStackWrapper {
@BeforeAll
public static void load() {
MockBukkit.mock();
}
@AfterAll
public static void unload() {
MockBukkit.unmock();
}
@Test
public void testEquality() {
ItemStack item = new CustomItem(Material.LAVA_BUCKET, "&4SuperHot.exe", "", "&6Hello");
ItemStackWrapper wrapper = new ItemStackWrapper(item);
Assertions.assertEquals(item.getType(), wrapper.getType());
Assertions.assertEquals(item.getItemMeta(), wrapper.getItemMeta());
Assertions.assertTrue(SlimefunUtils.isItemSimilar(wrapper, item, true));
}
@Test
public void testImmutability() {
ItemStack item = new CustomItem(Material.LAVA_BUCKET, "&4SuperHot.exe", "", "&6Hello");
ItemStackWrapper wrapper = new ItemStackWrapper(item);
Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.setType(Material.BEDROCK));
Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.setAmount(3));
Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.setItemMeta(item.getItemMeta()));
Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.addUnsafeEnchantment(null, 1));
}
}