mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Added ItemStackWrapper Unit Tests
This commit is contained in:
parent
fe499a357e
commit
990b717339
@ -21,7 +21,7 @@ public final class ItemStackWrapper extends ItemStack {
|
|||||||
private ItemMeta meta;
|
private ItemMeta meta;
|
||||||
|
|
||||||
public ItemStackWrapper(ItemStack item) {
|
public ItemStackWrapper(ItemStack item) {
|
||||||
super(item.getType(), item.getAmount());
|
super(item.getType());
|
||||||
meta = item.getItemMeta();
|
meta = item.getItemMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public final class ItemStackWrapper extends ItemStack {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
throw new UnsupportedOperationException("ItemStackWrapper do not allow .equals()");
|
throw new UnsupportedOperationException("ItemStackWrappers do not allow .equals()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user