Fixing tests

This commit is contained in:
tastybento 2024-12-30 16:05:00 -08:00
parent b5f7acaf76
commit 6981525077
3 changed files with 18 additions and 21 deletions

View File

@ -129,6 +129,7 @@ public abstract class AbstractCommonSetup {
when(location.getBlockY()).thenReturn(0); when(location.getBlockY()).thenReturn(0);
when(location.getBlockZ()).thenReturn(0); when(location.getBlockZ()).thenReturn(0);
when(location.toVector()).thenReturn(new Vector(0,0,0)); when(location.toVector()).thenReturn(new Vector(0,0,0));
when(location.clone()).thenReturn(location); // Paper
// Players Manager and meta data // Players Manager and meta data
PlayersManager pm = mock(PlayersManager.class); PlayersManager pm = mock(PlayersManager.class);

View File

@ -34,7 +34,6 @@ import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -68,7 +67,6 @@ import world.bentobox.bentobox.util.Util;
public class ChestDamageListenerTest extends AbstractCommonSetup public class ChestDamageListenerTest extends AbstractCommonSetup
{ {
private Location location;
private BentoBox plugin; private BentoBox plugin;
private World world; private World world;
@ -104,11 +102,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta); when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
when(Bukkit.getItemFactory()).thenReturn(itemFactory); when(Bukkit.getItemFactory()).thenReturn(itemFactory);
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger()); when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
location = mock(Location.class);
when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(0);
when(location.getBlockY()).thenReturn(0);
when(location.getBlockZ()).thenReturn(0);
PowerMockito.mockStatic(Flags.class); PowerMockito.mockStatic(Flags.class);
FlagsManager flagsManager = new FlagsManager(plugin); FlagsManager flagsManager = new FlagsManager(plugin);
@ -180,28 +174,37 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
* Test method for {@link ChestDamageListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}. * Test method for {@link ChestDamageListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}.
*/ */
@Test @Test
@Ignore("Fixes required for failures PaperAPI")
public void testOnExplosionChestDamageNotAllowed() { public void testOnExplosionChestDamageNotAllowed() {
// Srt the flag to not allow chest damage
Flags.CHEST_DAMAGE.setSetting(world, false); Flags.CHEST_DAMAGE.setSetting(world, false);
// Set the entity that is causing the damage (TNT)
Entity entity = mock(Entity.class); Entity entity = mock(Entity.class);
when(entity.getType()).thenReturn(EntityType.TNT); when(entity.getType()).thenReturn(EntityType.TNT);
// Create a list of blocks that will potentially be damaged by TNT
List<Block> list = new ArrayList<>(); List<Block> list = new ArrayList<>();
Block chest = mock(Block.class); Block chest = mock(Block.class);
when(chest.getType()).thenReturn(Material.CHEST); when(chest.getType()).thenReturn(Material.CHEST); // Regular chest
when(chest.getLocation()).thenReturn(location); when(chest.getLocation()).thenReturn(location);
Block trappedChest = mock(Block.class); Block trappedChest = mock(Block.class);
when(trappedChest.getType()).thenReturn(Material.TRAPPED_CHEST); when(trappedChest.getType()).thenReturn(Material.TRAPPED_CHEST);// Trapped chest
when(trappedChest.getLocation()).thenReturn(location); when(trappedChest.getLocation()).thenReturn(location);
Block stone = mock(Block.class); Block stone = mock(Block.class);
when(stone.getType()).thenReturn(Material.STONE); when(stone.getType()).thenReturn(Material.STONE); // Stone
when(stone.getLocation()).thenReturn(location); when(stone.getLocation()).thenReturn(location);
list.add(chest); list.add(chest);
list.add(trappedChest); list.add(trappedChest);
list.add(stone); list.add(stone);
// Create the event
EntityExplodeEvent e = getExplodeEvent(entity, location, list); EntityExplodeEvent e = getExplodeEvent(entity, location, list);
// Listener to test
ChestDamageListener listener = new ChestDamageListener(); ChestDamageListener listener = new ChestDamageListener();
listener.setPlugin(plugin); listener.setPlugin(plugin);
listener.onExplosion(e); listener.onExplosion(e);
// Verify
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
assertEquals(1, e.blockList().size()); assertEquals(1, e.blockList().size());
assertFalse(e.blockList().contains(chest)); assertFalse(e.blockList().contains(chest));

View File

@ -24,7 +24,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
@ -52,8 +51,6 @@ public class WitherListenerTest extends AbstractCommonSetup {
private WitherListener wl; private WitherListener wl;
@Mock @Mock
private Location location;
@Mock
private Location location2; private Location location2;
@Mock @Mock
private World world; private World world;
@ -82,15 +79,11 @@ public class WitherListenerTest extends AbstractCommonSetup {
when(ws.getWorldFlags()).thenReturn(map); when(ws.getWorldFlags()).thenReturn(map);
when(iwm.getWorldSettings(any())).thenReturn(ws); when(iwm.getWorldSettings(any())).thenReturn(ws);
when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(0);
when(location.getBlockY()).thenReturn(0);
when(location.getBlockZ()).thenReturn(0);
when(location2.getWorld()).thenReturn(world2); when(location2.getWorld()).thenReturn(world2);
when(location2.getBlockX()).thenReturn(0); when(location2.getBlockX()).thenReturn(0);
when(location2.getBlockY()).thenReturn(0); when(location2.getBlockY()).thenReturn(0);
when(location2.getBlockZ()).thenReturn(0); when(location2.getBlockZ()).thenReturn(0);
when(location2.clone()).thenReturn(location2); // Paper
blocks = new ArrayList<>(); blocks = new ArrayList<>();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -119,12 +112,12 @@ public class WitherListenerTest extends AbstractCommonSetup {
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.WitherListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}. * Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.WitherListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}.
*/ */
@Test @Test
@Ignore("Fixes required for failures PaperAPI")
public void testOnExplosionWither() { public void testOnExplosionWither() {
Entity entity = mock(Entity.class); Entity entity = mock(Entity.class);
when(entity.getLocation()).thenReturn(location); when(entity.getLocation()).thenReturn(location);
when(entity.getWorld()).thenReturn(world); when(entity.getWorld()).thenReturn(world);
when(entity.getType()).thenReturn(EntityType.WITHER); when(entity.getType()).thenReturn(EntityType.WITHER);
when(location.clone()).thenReturn(location);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks); EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e); wl.onExplosion(e);
assertTrue(blocks.isEmpty()); assertTrue(blocks.isEmpty());
@ -165,12 +158,12 @@ public class WitherListenerTest extends AbstractCommonSetup {
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.WitherListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}. * Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.WitherListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}.
*/ */
@Test @Test
@Ignore("Fixes required for failures PaperAPI")
public void testOnExplosionWitherSkull() { public void testOnExplosionWitherSkull() {
Entity entity = mock(Entity.class); Entity entity = mock(Entity.class);
when(entity.getLocation()).thenReturn(location); when(entity.getLocation()).thenReturn(location);
when(entity.getWorld()).thenReturn(world); when(entity.getWorld()).thenReturn(world);
when(entity.getType()).thenReturn(EntityType.WITHER_SKULL); when(entity.getType()).thenReturn(EntityType.WITHER_SKULL);
when(location.clone()).thenReturn(location);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks); EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e); wl.onExplosion(e);
assertTrue(blocks.isEmpty()); assertTrue(blocks.isEmpty());