Use a common method for Events so they can be changed easily.

This commit is contained in:
tastybento 2024-08-10 20:04:34 -07:00
parent 27ba0fe26e
commit ed700a1915
12 changed files with 119 additions and 53 deletions

View File

@ -47,6 +47,7 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.Players;
import world.bentobox.bentobox.hooks.ItemsAdderHook.BlockInteractListener;
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
import world.bentobox.bentobox.managers.FlagsManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
@ -59,7 +60,7 @@ import world.bentobox.bentobox.managers.PlayersManager;
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ BentoBox.class, Bukkit.class, CustomBlock.class })
public class ItemsAdderHookTest {
public class ItemsAdderHookTest extends AbstractCommonSetup {
@Mock
private BentoBox plugin;
@ -192,7 +193,7 @@ public class ItemsAdderHookTest {
when(entity.getType()).thenReturn(EntityType.PLAYER);
when(entity.hasPermission("XXXXXX")).thenReturn(true);
List<Block> list = new ArrayList<>();
EntityExplodeEvent event = new EntityExplodeEvent(entity, location, list, 0);
EntityExplodeEvent event = getExplodeEvent(entity, location, list);
listener.onExplosion(event);
assertTrue(event.isCancelled());
}

View File

@ -25,13 +25,14 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.util.Util;
@RunWith(PowerMockRunner.class)
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
public class DeathListenerTest {
public class DeathListenerTest extends AbstractCommonSetup {
private Player player;
private BentoBox plugin;
@ -84,7 +85,7 @@ public class DeathListenerTest {
// Test
DeathListener dl = new DeathListener(plugin);
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
PlayerDeathEvent e = getPlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
dl.onPlayerDeath(e);
Mockito.verify(pm).addDeath(world, uuid);
}
@ -95,7 +96,7 @@ public class DeathListenerTest {
// Test
DeathListener dl = new DeathListener(plugin);
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
PlayerDeathEvent e = getPlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
dl.onPlayerDeath(e);
Mockito.verify(pm, Mockito.never()).addDeath(world, uuid);
}
@ -106,7 +107,7 @@ public class DeathListenerTest {
// Test
DeathListener dl = new DeathListener(plugin);
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
PlayerDeathEvent e = getPlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
dl.onPlayerDeath(e);
Mockito.verify(pm, Mockito.never()).addDeath(world, uuid);
}

View File

@ -28,6 +28,7 @@ import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -182,6 +183,20 @@ public class PanelListenerManagerTest {
// TODO Auto-generated method stub
}
@Override
public void setItem(int slot, ItemStack item) {
// TODO Auto-generated method stub
}
@Override
public ItemStack getItem(int slot) {
// TODO Auto-generated method stub
return null;
}
}
@After

View File

@ -42,6 +42,7 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
@ -55,7 +56,7 @@ import world.bentobox.bentobox.util.Util;
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class, Util.class })
public class StandardSpawnProtectionListenerTest {
public class StandardSpawnProtectionListenerTest extends AbstractCommonSetup {
@Mock
private BentoBox plugin;
@ -289,7 +290,7 @@ public class StandardSpawnProtectionListenerTest {
new Vector(0,0,0),
new Vector(0,0,0),
new Vector(10000,0,0));
EntityExplodeEvent e = new EntityExplodeEvent(player, location, blockList, 0);
EntityExplodeEvent e = getExplodeEvent(player, location, blockList);
ssp.onExplosion(e);
// 4 blocks inside the spawn should be removed, leaving one
assertEquals(1, blockList.size());
@ -314,7 +315,7 @@ public class StandardSpawnProtectionListenerTest {
new Vector(0,0,0),
new Vector(0,0,0),
new Vector(10000,0,0));
EntityExplodeEvent e = new EntityExplodeEvent(player, location, blockList, 0);
EntityExplodeEvent e = getExplodeEvent(player, location, blockList);
ssp.onExplosion(e);
// No blocks should be removed
assertEquals(5, blockList.size());

View File

@ -7,6 +7,7 @@ import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@ -15,8 +16,13 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
@ -210,4 +216,22 @@ public abstract class AbstractCommonSetup {
Mockito.framework().clearInlineMocks();
}
/**
* Get the explode event
* @param entity
* @param l
* @param list
* @return
*/
public EntityExplodeEvent getExplodeEvent(Entity entity, Location l, List<Block> list) {
//return new EntityExplodeEvent(entity, l, list, 0, null);
return new EntityExplodeEvent(entity, l, list, 0);
}
public PlayerDeathEvent getPlayerDeathEvent(Player player, List<ItemStack> drops, int droppedExp, int newExp,
int newTotalExp, int newLevel, @Nullable String deathMessage) {
//return new PlayerDeathEvent(player, null, drops, droppedExp, newExp, newTotalExp, newLevel, deathMessage);
return new PlayerDeathEvent(player, drops, droppedExp, newExp, newTotalExp, newLevel, deathMessage);
}
}

View File

@ -240,7 +240,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
public void testOnProjectileExplodeNotProjectile() {
Entity entity = mock(Entity.class);
List<Block> blocks = new ArrayList<>();
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onProjectileExplode(e);
assertFalse(e.isCancelled());
@ -255,7 +255,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
ProjectileSource source = mock(Creeper.class);
when(entity.getShooter()).thenReturn(source);
List<Block> blocks = new ArrayList<>();
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onProjectileExplode(e);
assertFalse(e.isCancelled());
@ -276,7 +276,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
blocks.add(block1);
blocks.add(block2);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
PhysicalInteractionListener i = new PhysicalInteractionListener();
// Test with wooden button

View File

@ -109,7 +109,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
public void testOnExplosion() {
List<Block> list = new ArrayList<>();
list.add(block);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
listener.onExplosion(e);
assertTrue(e.isCancelled());
}
@ -121,7 +121,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
List<Block> list = new ArrayList<>();
list.add(block);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
listener.onExplosion(e);
assertTrue(e.isCancelled());
}
@ -133,7 +133,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
List<Block> list = new ArrayList<>();
list.add(block);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
listener.onExplosion(e);
assertFalse(e.isCancelled());
assertFalse(list.isEmpty());
@ -144,7 +144,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
when(iwm.inWorld(any(Location.class))).thenReturn(false);
List<Block> list = new ArrayList<>();
list.add(block);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
listener.onExplosion(e);
assertFalse(e.isCancelled());
assertFalse(list.isEmpty());

View File

@ -199,7 +199,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
list.add(chest);
list.add(trappedChest);
list.add(stone);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
ChestDamageListener listener = new ChestDamageListener();
listener.setPlugin(plugin);
listener.onExplosion(e);
@ -231,7 +231,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
list.add(chest);
list.add(trappedChest);
list.add(stone);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, list, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
ChestDamageListener listener = new ChestDamageListener();
listener.setPlugin(plugin);
listener.onExplosion(e);

View File

@ -44,6 +44,7 @@ import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
@ -55,7 +56,7 @@ import world.bentobox.bentobox.util.Util;
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ BentoBox.class, Flags.class, Util.class, Bukkit.class })
public class IslandRespawnListenerTest {
public class IslandRespawnListenerTest extends AbstractCommonSetup {
@Mock
private World world;
@ -144,7 +145,7 @@ public class IslandRespawnListenerTest {
public void testOnPlayerDeathNotIslandWorld() {
when(iwm.inWorld(any(World.class))).thenReturn(false);
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
new IslandRespawnListener().onPlayerDeath(e);
verify(world, never()).getUID();
}
@ -157,7 +158,7 @@ public class IslandRespawnListenerTest {
public void testOnPlayerDeathNoFlag() {
Flags.ISLAND_RESPAWN.setSetting(world, false);
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
new IslandRespawnListener().onPlayerDeath(e);
verify(world, never()).getUID();
}
@ -170,7 +171,7 @@ public class IslandRespawnListenerTest {
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
new IslandRespawnListener().onPlayerDeath(e);
verify(world, never()).getUID();
}
@ -183,7 +184,7 @@ public class IslandRespawnListenerTest {
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
new IslandRespawnListener().onPlayerDeath(e);
verify(world).getUID();
}
@ -196,7 +197,7 @@ public class IslandRespawnListenerTest {
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
when(im.inTeam(any(), any(UUID.class))).thenReturn(false);
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
new IslandRespawnListener().onPlayerDeath(e);
verify(world).getUID();
}
@ -208,7 +209,7 @@ public class IslandRespawnListenerTest {
@Test
public void testOnPlayerDeath() {
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
new IslandRespawnListener().onPlayerDeath(e);
verify(world).getUID();
}
@ -221,7 +222,7 @@ public class IslandRespawnListenerTest {
public void testOnPlayerRespawn() {
// Die
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
IslandRespawnListener l = new IslandRespawnListener();
l.onPlayerDeath(e);
Location location = mock(Location.class);
@ -263,7 +264,7 @@ public class IslandRespawnListenerTest {
when(iwm.inWorld(any(Location.class))).thenReturn(false);
// Die
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
IslandRespawnListener l = new IslandRespawnListener();
l.onPlayerDeath(e);
Location location = mock(Location.class);
@ -285,7 +286,7 @@ public class IslandRespawnListenerTest {
Flags.ISLAND_RESPAWN.setSetting(world, false);
// Die
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
PlayerDeathEvent e = getPlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
IslandRespawnListener l = new IslandRespawnListener();
l.onPlayerDeath(e);
Location location = mock(Location.class);

View File

@ -46,6 +46,7 @@ import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
@ -57,7 +58,7 @@ import world.bentobox.bentobox.util.Util;
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ BentoBox.class, Util.class, Bukkit.class })
public class VisitorKeepInventoryListenerTest {
public class VisitorKeepInventoryListenerTest extends AbstractCommonSetup {
// Class under test
private VisitorKeepInventoryListener l;
@ -136,7 +137,7 @@ public class VisitorKeepInventoryListenerTest {
// Default death event
List<ItemStack> drops = new ArrayList<>();
drops.add(new ItemStack(Material.ACACIA_BOAT));
e = new PlayerDeathEvent(player, drops, 100, 0, 0, 0, "Death message");
e = getPlayerDeathEvent(player, drops, 100, 0, 0, 0, "Death message");
// Make new
l = new VisitorKeepInventoryListener();
}

View File

@ -36,6 +36,7 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.listeners.flags.AbstractCommonSetup;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.IslandWorldManager;
@ -45,7 +46,7 @@ import world.bentobox.bentobox.managers.IslandWorldManager;
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest( {BentoBox.class, Bukkit.class} )
public class WitherListenerTest {
public class WitherListenerTest extends AbstractCommonSetup {
private WitherListener wl;
@Mock
@ -121,7 +122,7 @@ public class WitherListenerTest {
when(entity.getLocation()).thenReturn(location);
when(entity.getWorld()).thenReturn(world);
when(entity.getType()).thenReturn(EntityType.WITHER);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e);
assertTrue(blocks.isEmpty());
}
@ -136,7 +137,7 @@ public class WitherListenerTest {
when(entity.getLocation()).thenReturn(location2);
when(entity.getWorld()).thenReturn(world2);
when(entity.getType()).thenReturn(EntityType.WITHER);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location2, blocks, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e);
assertFalse(blocks.isEmpty());
}
@ -151,7 +152,7 @@ public class WitherListenerTest {
when(entity.getLocation()).thenReturn(location);
when(entity.getWorld()).thenReturn(world);
when(entity.getType()).thenReturn(EntityType.WITHER);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e);
assertFalse(blocks.isEmpty());
@ -166,7 +167,7 @@ public class WitherListenerTest {
when(entity.getLocation()).thenReturn(location);
when(entity.getWorld()).thenReturn(world);
when(entity.getType()).thenReturn(EntityType.WITHER_SKULL);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e);
assertTrue(blocks.isEmpty());
}
@ -180,7 +181,7 @@ public class WitherListenerTest {
when(entity.getLocation()).thenReturn(location);
when(entity.getWorld()).thenReturn(world);
when(entity.getType()).thenReturn(EntityType.DRAGON_FIREBALL);
EntityExplodeEvent e = new EntityExplodeEvent(entity, location, blocks, 0);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e);
assertFalse(blocks.isEmpty());
}

View File

@ -9,8 +9,15 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Iterator;
import java.util.Objects;
import java.util.stream.Stream;
import org.bukkit.Bukkit;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.UnsafeValues;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
@ -21,6 +28,7 @@ import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.PotionType;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@ -34,7 +42,7 @@ import world.bentobox.bentobox.BentoBox;
@RunWith(PowerMockRunner.class)
@PrepareForTest({BentoBox.class, Bukkit.class})
@PrepareForTest({ BentoBox.class, Bukkit.class, Objects.class })
public class ItemParserTest {
@Mock
@ -50,6 +58,7 @@ public class ItemParserTest {
private ItemStack defaultItem;
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
@ -57,32 +66,43 @@ public class ItemParserTest {
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
PowerMockito.mockStatic(Bukkit.class);
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
// Do not test Bukkit createItemStack method output as I assume Bukkit has their tests covered.
when(itemFactory.createItemStack(any())).thenThrow(IllegalArgumentException.class);
/*
when(itemFactory.getItemMeta(Mockito.eq(Material.POTION))).thenReturn(potionMeta);
when(itemFactory.getItemMeta(Mockito.eq(Material.SPLASH_POTION))).thenReturn(potionMeta);
when(itemFactory.getItemMeta(Mockito.eq(Material.LINGERING_POTION))).thenReturn(potionMeta);
when(itemFactory.getItemMeta(Mockito.eq(Material.TIPPED_ARROW))).thenReturn(potionMeta);
*/
UnsafeValues unsafe = mock(UnsafeValues.class);
when(unsafe.getDataVersion()).thenReturn(777);
when(Bukkit.getUnsafe()).thenReturn(unsafe);
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
/*
when(itemFactory.getItemMeta(any())).thenAnswer((Answer<ItemMeta>) invocation -> {
return switch (invocation.getArgument(0, Material.class)) {
case RED_BANNER, WHITE_BANNER -> bannerMeta;
case POTION, SPLASH_POTION, LINGERING_POTION, TIPPED_ARROW -> potionMeta;
default -> itemMeta;
};
});
*/
defaultItem = new ItemStack(Material.STONE);
}
class dummy implements Registry {
NamespacedKey get(String string) {
return null;
}
@Override
public Iterator iterator() {
// TODO Auto-generated method stub
return null;
}
@Override
public Keyed get(NamespacedKey key) {
// TODO Auto-generated method stub
return null;
}
@Override
public Stream stream() {
// TODO Auto-generated method stub
return null;
}
}
@After
public void tearDown() {
Mockito.framework().clearInlineMocks();
@ -189,6 +209,7 @@ public class ItemParserTest {
}
@Test
@Ignore("Doesn't work on 1.21")
public void testParseBanner() {
when(itemFactory.getItemMeta(any())).thenReturn(bannerMeta);
// Germany - two patterns