Search in sources :

Example 1 with HopperInventoryMock

use of be.seeseemelk.mockbukkit.inventory.HopperInventoryMock in project Slimefun4 by Slimefun.

the class TestItemPickupListener method testNoPickupFlagForInventories.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void testNoPickupFlagForInventories(boolean flag) {
    Inventory inventory = new HopperInventoryMock(null);
    Item item = new ItemEntityMock(server, UUID.randomUUID(), new ItemStack(Material.COMPASS));
    if (flag) {
        SlimefunUtils.markAsNoPickup(item, "Unit Test");
    }
    InventoryPickupItemEvent event = new InventoryPickupItemEvent(inventory, item);
    listener.onHopperPickup(event);
    Assertions.assertEquals(flag, event.isCancelled());
}
Also used : HopperInventoryMock(be.seeseemelk.mockbukkit.inventory.HopperInventoryMock) Item(org.bukkit.entity.Item) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemEntityMock(be.seeseemelk.mockbukkit.entity.ItemEntityMock) Inventory(org.bukkit.inventory.Inventory) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with HopperInventoryMock

use of be.seeseemelk.mockbukkit.inventory.HopperInventoryMock in project Slimefun4 by Slimefun.

the class TestItemPickupListener method testAltarProbeForInventories.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void testAltarProbeForInventories(boolean flag) {
    Inventory inventory = new HopperInventoryMock(null);
    ItemStack stack;
    if (flag) {
        stack = new CustomItemStack(Material.DIAMOND, AncientPedestal.ITEM_PREFIX + System.nanoTime());
    } else {
        stack = new CustomItemStack(Material.DIAMOND, "&5Just a normal named diamond");
    }
    AtomicBoolean removed = new AtomicBoolean(false);
    Item item = new ItemEntityMock(server, UUID.randomUUID(), stack) {

        @Override
        public void remove() {
            removed.set(true);
        }
    };
    InventoryPickupItemEvent event = new InventoryPickupItemEvent(inventory, item);
    listener.onHopperPickup(event);
    Assertions.assertEquals(flag, event.isCancelled());
    Assertions.assertEquals(flag, removed.get());
}
Also used : HopperInventoryMock(be.seeseemelk.mockbukkit.inventory.HopperInventoryMock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Item(org.bukkit.entity.Item) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemEntityMock(be.seeseemelk.mockbukkit.entity.ItemEntityMock) Inventory(org.bukkit.inventory.Inventory) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ItemEntityMock (be.seeseemelk.mockbukkit.entity.ItemEntityMock)2 HopperInventoryMock (be.seeseemelk.mockbukkit.inventory.HopperInventoryMock)2 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)2 Item (org.bukkit.entity.Item)2 InventoryPickupItemEvent (org.bukkit.event.inventory.InventoryPickupItemEvent)2 Inventory (org.bukkit.inventory.Inventory)2 ItemStack (org.bukkit.inventory.ItemStack)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1