mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Added Unit Tests for the Cooler Listener
This commit is contained in:
parent
9b2c378c3a
commit
8bd653a1b5
@ -0,0 +1,83 @@
|
|||||||
|
package io.github.thebusybiscuit.slimefun4.testing.tests.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
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.Test;
|
||||||
|
|
||||||
|
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||||
|
import be.seeseemelk.mockbukkit.ServerMock;
|
||||||
|
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.player.PlayerBackpack;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.Cooler;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.items.food.Juice;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.BackpackListener;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.listeners.CoolerListener;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
|
||||||
|
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||||
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
|
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||||
|
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||||
|
|
||||||
|
public class TestCoolerListener {
|
||||||
|
|
||||||
|
private static ServerMock server;
|
||||||
|
private static CoolerListener listener;
|
||||||
|
|
||||||
|
private static Cooler cooler;
|
||||||
|
private static Juice juice;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void load() {
|
||||||
|
server = MockBukkit.mock();
|
||||||
|
SlimefunPlugin plugin = MockBukkit.load(SlimefunPlugin.class);
|
||||||
|
|
||||||
|
Category category = new Category(new NamespacedKey(plugin, "cooler_test"), new CustomItem(Material.SNOWBALL, "Mr. Freeze"));
|
||||||
|
SlimefunItemStack item = new SlimefunItemStack("TEST_COOLER", Material.SNOWBALL, "&6Test Cooler", "", "&7ID: <ID>");
|
||||||
|
cooler = new Cooler(18, category, item, RecipeType.NULL, new ItemStack[9]);
|
||||||
|
cooler.register(plugin);
|
||||||
|
|
||||||
|
SlimefunItemStack juiceItem = new SlimefunItemStack("TEST_JUICE", Color.RED, new PotionEffect(PotionEffectType.HEALTH_BOOST, 6, 0), "&4Test Juice");
|
||||||
|
juice = new Juice(category, juiceItem, RecipeType.NULL, new ItemStack[9]);
|
||||||
|
juice.register(plugin);
|
||||||
|
|
||||||
|
listener = new CoolerListener(plugin, cooler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public static void unload() {
|
||||||
|
MockBukkit.unmock();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public 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 {
|
||||||
|
Player player = server.addPlayer();
|
||||||
|
PlayerProfile profile = TestUtilities.awaitProfile(player);
|
||||||
|
PlayerBackpack backpack = profile.createBackpack(cooler.getSize());
|
||||||
|
backpack.getInventory().setItem(0, juice.getItem().clone());
|
||||||
|
|
||||||
|
ItemStack personalCooler = cooler.getItem().clone();
|
||||||
|
new BackpackListener().setBackpackId(player, personalCooler, 1, backpack.getId());
|
||||||
|
player.getInventory().setItem(7, personalCooler);
|
||||||
|
|
||||||
|
FoodLevelChangeEvent event = new FoodLevelChangeEvent(player, 16);
|
||||||
|
listener.onHungerLoss(event);
|
||||||
|
Assertions.assertTrue(player.hasPotionEffect(PotionEffectType.HEALTH_BOOST));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user