mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-09 09:57:40 +01:00
Fixing tests
This commit is contained in:
parent
b5f7acaf76
commit
6981525077
@ -129,6 +129,7 @@ public abstract class AbstractCommonSetup {
|
||||
when(location.getBlockY()).thenReturn(0);
|
||||
when(location.getBlockZ()).thenReturn(0);
|
||||
when(location.toVector()).thenReturn(new Vector(0,0,0));
|
||||
when(location.clone()).thenReturn(location); // Paper
|
||||
|
||||
// Players Manager and meta data
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
|
@ -34,7 +34,6 @@ import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
@ -68,7 +67,6 @@ import world.bentobox.bentobox.util.Util;
|
||||
public class ChestDamageListenerTest extends AbstractCommonSetup
|
||||
{
|
||||
|
||||
private Location location;
|
||||
private BentoBox plugin;
|
||||
private World world;
|
||||
|
||||
@ -104,11 +102,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
|
||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||
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);
|
||||
|
||||
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
|
||||
@Ignore("Fixes required for failures PaperAPI")
|
||||
public void testOnExplosionChestDamageNotAllowed() {
|
||||
// Srt the flag to not allow chest damage
|
||||
Flags.CHEST_DAMAGE.setSetting(world, false);
|
||||
// Set the entity that is causing the damage (TNT)
|
||||
Entity entity = mock(Entity.class);
|
||||
when(entity.getType()).thenReturn(EntityType.TNT);
|
||||
|
||||
// Create a list of blocks that will potentially be damaged by TNT
|
||||
List<Block> list = new ArrayList<>();
|
||||
Block chest = mock(Block.class);
|
||||
when(chest.getType()).thenReturn(Material.CHEST);
|
||||
when(chest.getType()).thenReturn(Material.CHEST); // Regular chest
|
||||
when(chest.getLocation()).thenReturn(location);
|
||||
|
||||
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);
|
||||
|
||||
Block stone = mock(Block.class);
|
||||
when(stone.getType()).thenReturn(Material.STONE);
|
||||
when(stone.getType()).thenReturn(Material.STONE); // Stone
|
||||
when(stone.getLocation()).thenReturn(location);
|
||||
list.add(chest);
|
||||
list.add(trappedChest);
|
||||
list.add(stone);
|
||||
// Create the event
|
||||
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
|
||||
// Listener to test
|
||||
ChestDamageListener listener = new ChestDamageListener();
|
||||
listener.setPlugin(plugin);
|
||||
listener.onExplosion(e);
|
||||
|
||||
// Verify
|
||||
assertFalse(e.isCancelled());
|
||||
assertEquals(1, e.blockList().size());
|
||||
assertFalse(e.blockList().contains(chest));
|
||||
|
@ -24,7 +24,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
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;
|
||||
@ -52,8 +51,6 @@ public class WitherListenerTest extends AbstractCommonSetup {
|
||||
|
||||
private WitherListener wl;
|
||||
@Mock
|
||||
private Location location;
|
||||
@Mock
|
||||
private Location location2;
|
||||
@Mock
|
||||
private World world;
|
||||
@ -82,15 +79,11 @@ public class WitherListenerTest extends AbstractCommonSetup {
|
||||
when(ws.getWorldFlags()).thenReturn(map);
|
||||
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.getBlockX()).thenReturn(0);
|
||||
when(location2.getBlockY()).thenReturn(0);
|
||||
when(location2.getBlockZ()).thenReturn(0);
|
||||
when(location2.clone()).thenReturn(location2); // Paper
|
||||
|
||||
blocks = new ArrayList<>();
|
||||
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
|
||||
@Ignore("Fixes required for failures PaperAPI")
|
||||
public void testOnExplosionWither() {
|
||||
Entity entity = mock(Entity.class);
|
||||
when(entity.getLocation()).thenReturn(location);
|
||||
when(entity.getWorld()).thenReturn(world);
|
||||
when(entity.getType()).thenReturn(EntityType.WITHER);
|
||||
when(location.clone()).thenReturn(location);
|
||||
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||
wl.onExplosion(e);
|
||||
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
|
||||
@Ignore("Fixes required for failures PaperAPI")
|
||||
public void testOnExplosionWitherSkull() {
|
||||
Entity entity = mock(Entity.class);
|
||||
when(entity.getLocation()).thenReturn(location);
|
||||
when(entity.getWorld()).thenReturn(world);
|
||||
when(entity.getType()).thenReturn(EntityType.WITHER_SKULL);
|
||||
when(location.clone()).thenReturn(location);
|
||||
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
|
||||
wl.onExplosion(e);
|
||||
assertTrue(blocks.isEmpty());
|
||||
|
Loading…
Reference in New Issue
Block a user