Added inWorld(World.class) to IWM

This had a ripple affect through the tests because now there are two
inWorld() methods - one for Location and one for World.
This commit is contained in:
tastybento 2018-09-29 09:01:20 -07:00
parent f110aedc69
commit 0f5ab8ab7d
22 changed files with 153 additions and 90 deletions

View File

@ -78,7 +78,17 @@ public class IslandWorldManager {
* @return true if in a world or false if not * @return true if in a world or false if not
*/ */
public boolean inWorld(Location loc) { public boolean inWorld(Location loc) {
return worlds.containsKey(Util.getWorld(loc.getWorld())); return inWorld(loc.getWorld());
}
/**
* Checks if a world is any of the island worlds
*
* @param world world
* @return true if in a world or false if not
*/
public boolean inWorld(World world) {
return worlds.containsKey(Util.getWorld(world));
} }
/** /**

View File

@ -146,7 +146,8 @@ public class TestBSkyBlock {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
Mockito.when(plugin.getIWM()).thenReturn(iwm); Mockito.when(plugin.getIWM()).thenReturn(iwm);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world); when(Util.getWorld(Mockito.any())).thenReturn(world);
// We want the read tabLimit call here // We want the read tabLimit call here

View File

@ -184,7 +184,8 @@ public class CycleClickTest {
// IslandWorldManager // IslandWorldManager
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock"); when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
// Util // Util
@ -195,7 +196,8 @@ public class CycleClickTest {
@Test @Test
public void testNotInWorld() { public void testNotInWorld() {
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
CycleClick udc = new CycleClick("LOCK"); CycleClick udc = new CycleClick("LOCK");
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5)); assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.wrong-world")); Mockito.verify(user).sendMessage(Mockito.eq("general.errors.wrong-world"));

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.flags.clicklisteners; package world.bentobox.bentobox.api.flags.clicklisteners;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -55,7 +56,8 @@ public class IslandToggleClickTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin); Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager // Island World Manager
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock"); when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
@ -93,7 +95,8 @@ public class IslandToggleClickTest {
@Test @Test
public void testOnClickWrongWorld() { public void testOnClickWrongWorld() {
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
listener.onClick(panel, user, ClickType.LEFT, 0); listener.onClick(panel, user, ClickType.LEFT, 0);
Mockito.verify(user).sendMessage("general.errors.wrong-world"); Mockito.verify(user).sendMessage("general.errors.wrong-world");
} }

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.flags.clicklisteners; package world.bentobox.bentobox.api.flags.clicklisteners;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -48,7 +49,8 @@ public class WorldToggleClickTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin); Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager // Island World Manager
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock"); when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
@ -77,7 +79,8 @@ public class WorldToggleClickTest {
@Test @Test
public void testOnClickWrongWorld() { public void testOnClickWrongWorld() {
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
listener.onClick(panel, user, ClickType.LEFT, 0); listener.onClick(panel, user, ClickType.LEFT, 0);
Mockito.verify(user).sendMessage("general.errors.wrong-world"); Mockito.verify(user).sendMessage("general.errors.wrong-world");
} }

View File

@ -52,7 +52,8 @@ public class BannedVisitorCommandsTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin); Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager // Island World Manager
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock"); when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
when(iwm.getVisitorBannedCommands(Mockito.any())).thenReturn(new ArrayList<>()); when(iwm.getVisitorBannedCommands(Mockito.any())).thenReturn(new ArrayList<>());
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
@ -105,13 +106,15 @@ public class BannedVisitorCommandsTest {
BannedVisitorCommands bvc = new BannedVisitorCommands(plugin); BannedVisitorCommands bvc = new BannedVisitorCommands(plugin);
// Not in world // Not in world
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
bvc.onVisitorCommand(e); bvc.onVisitorCommand(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// In world // In world
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
// Op // Op
when(player.isOp()).thenReturn(true); when(player.isOp()).thenReturn(true);
bvc.onVisitorCommand(e); bvc.onVisitorCommand(e);

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.listeners; package world.bentobox.bentobox.listeners;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -41,7 +42,8 @@ public class DeathListenerTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin); Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager // Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock"); when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
when(iwm.getVisitorBannedCommands(Mockito.any())).thenReturn(new ArrayList<>()); when(iwm.getVisitorBannedCommands(Mockito.any())).thenReturn(new ArrayList<>());
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);

View File

@ -90,7 +90,8 @@ public class NetherPortalsTest {
when(iwm.getEndWorld(Mockito.any())).thenReturn(end); when(iwm.getEndWorld(Mockito.any())).thenReturn(end);
when(iwm.getIslandWorld(Mockito.any())).thenReturn(world); when(iwm.getIslandWorld(Mockito.any())).thenReturn(world);
when(iwm.getNetherWorld(Mockito.any())).thenReturn(nether); when(iwm.getNetherWorld(Mockito.any())).thenReturn(nether);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(iwm.getNetherSpawnRadius(Mockito.any())).thenReturn(100); when(iwm.getNetherSpawnRadius(Mockito.any())).thenReturn(100);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
@ -147,6 +148,11 @@ public class NetherPortalsTest {
Util.setPlugin(plugin); Util.setPlugin(plugin);
} }
private void wrongWorld() {
when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
}
/** /**
* Test method for {@link world.bentobox.bentobox.listeners.NetherPortals#NetherPortals(world.bentobox.bentobox.BentoBox)}. * Test method for {@link world.bentobox.bentobox.listeners.NetherPortals#NetherPortals(world.bentobox.bentobox.BentoBox)}.
*/ */
@ -278,7 +284,7 @@ public class NetherPortalsTest {
// Right cause, end exists, wrong world // Right cause, end exists, wrong world
when(loc.getWorld()).thenReturn(mock(World.class)); when(loc.getWorld()).thenReturn(mock(World.class));
when(iwm.inWorld(any())).thenReturn(false); wrongWorld();
PlayerPortalEvent e = new PlayerPortalEvent(null, loc, null, null, TeleportCause.END_PORTAL); PlayerPortalEvent e = new PlayerPortalEvent(null, loc, null, null, TeleportCause.END_PORTAL);
when(iwm.isEndGenerate(world)).thenReturn(true); when(iwm.isEndGenerate(world)).thenReturn(true);
np.onEndIslandPortal(e); np.onEndIslandPortal(e);
@ -321,12 +327,13 @@ public class NetherPortalsTest {
Location from = mock(Location.class); Location from = mock(Location.class);
when(from.getWorld()).thenReturn(mock(World.class)); when(from.getWorld()).thenReturn(mock(World.class));
// Not in world // Not in world
when(iwm.inWorld(any())).thenReturn(false); wrongWorld();
EntityPortalEvent e = new EntityPortalEvent(ent, from, null, null); EntityPortalEvent e = new EntityPortalEvent(ent, from, null, null);
np.onEntityPortal(e); np.onEntityPortal(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// In world // In world
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
e = new EntityPortalEvent(ent, from, null, null); e = new EntityPortalEvent(ent, from, null, null);
np.onEntityPortal(e); np.onEntityPortal(e);
assertTrue(e.isCancelled()); assertTrue(e.isCancelled());
@ -353,7 +360,7 @@ public class NetherPortalsTest {
Location from = mock(Location.class); Location from = mock(Location.class);
when(from.getWorld()).thenReturn(mock(World.class)); when(from.getWorld()).thenReturn(mock(World.class));
// Not in world // Not in world
when(iwm.inWorld(any())).thenReturn(false); wrongWorld();
EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0); EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0);
@ -514,7 +521,7 @@ public class NetherPortalsTest {
NetherPortals np = new NetherPortals(plugin); NetherPortals np = new NetherPortals(plugin);
Location from = mock(Location.class); Location from = mock(Location.class);
when(from.getWorld()).thenReturn(mock(World.class)); when(from.getWorld()).thenReturn(mock(World.class));
when(iwm.inWorld(any())).thenReturn(false); wrongWorld();
PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL); PlayerPortalEvent e = new PlayerPortalEvent(null, from, null, null, TeleportCause.NETHER_PORTAL);
assertFalse(np.onNetherPortal(e)); assertFalse(np.onNetherPortal(e));
} }

View File

@ -117,7 +117,8 @@ public class ObsidianToLavaTest {
User.setPlugin(plugin); User.setPlugin(plugin);
// Put player in world // Put player in world
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
// Put player on island // Put player on island
when(im.userIsOnIsland(Mockito.any(), Mockito.any())).thenReturn(true); when(im.userIsOnIsland(Mockito.any(), Mockito.any())).thenReturn(true);
// Set as survival // Set as survival
@ -165,10 +166,12 @@ public class ObsidianToLavaTest {
PlayerInteractEvent event = new PlayerInteractEvent(who, action, item, clickedBlock, BlockFace.EAST); PlayerInteractEvent event = new PlayerInteractEvent(who, action, item, clickedBlock, BlockFace.EAST);
// Test not in world // Test not in world
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
assertFalse(listener.onPlayerInteract(event)); assertFalse(listener.onPlayerInteract(event));
// Put player in world // Put player in world
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
// Test different game modes // Test different game modes
for (GameMode gm : GameMode.values()) { for (GameMode gm : GameMode.values()) {

View File

@ -107,7 +107,8 @@ public class ChestDamageListenerTest {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Monsters and animals // Monsters and animals

View File

@ -94,7 +94,8 @@ public class EnderChestListenerTest {
Map<String, Boolean> worldFlags = new HashMap<>(); Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags); when(ws.getWorldFlags()).thenReturn(worldFlags);
// By default everything is in world // By default everything is in world
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
// Ender chest use is not allowed by default // Ender chest use is not allowed by default
Flags.ENDER_CHEST.setSetting(world, false); Flags.ENDER_CHEST.setSetting(world, false);
@ -147,7 +148,8 @@ public class EnderChestListenerTest {
BlockFace clickedBlockFace = BlockFace.EAST; BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace); PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
// Not in world // Not in world
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
new EnderChestListener().onEnderChestOpen(e); new EnderChestListener().onEnderChestOpen(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }

View File

@ -100,7 +100,8 @@ public class EndermanListenerTest {
// Worlds // Worlds
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Monsters and animals // Monsters and animals
@ -156,7 +157,8 @@ public class EndermanListenerTest {
*/ */
@Test @Test
public void testOnEndermanGriefWrongWorld() { public void testOnEndermanGriefWrongWorld() {
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EndermanListener listener = new EndermanListener(); EndermanListener listener = new EndermanListener();
Block to = mock(Block.class); Block to = mock(Block.class);
Material block = Material.ACACIA_DOOR; Material block = Material.ACACIA_DOOR;

View File

@ -150,7 +150,8 @@ public class EnterExitListenerTest {
// Island World Manager // Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Player's manager // Player's manager

View File

@ -95,7 +95,8 @@ public class FireListenerTest {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Monsters and animals // Monsters and animals

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.listeners.flags;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -65,7 +66,8 @@ public class InvincibleVisitorsListenerTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin); Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager // Island World Manager
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock"); when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
@ -186,7 +188,8 @@ public class InvincibleVisitorsListenerTest {
@Test @Test
public void testOnVisitorGetDamageNotInWorld() { public void testOnVisitorGetDamageNotInWorld() {
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D); EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D);
listener.onVisitorGetDamage(e); listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
@ -194,7 +197,8 @@ public class InvincibleVisitorsListenerTest {
@Test @Test
public void testOnVisitorGetDamageNotInIvSettings() { public void testOnVisitorGetDamageNotInIvSettings() {
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, 0D); EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, 0D);
listener.onVisitorGetDamage(e); listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());

View File

@ -4,6 +4,7 @@
package world.bentobox.bentobox.listeners.flags; package world.bentobox.bentobox.listeners.flags;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -76,7 +77,8 @@ public class IslandRespawnListenerTest {
// Island World Manager // Island World Manager
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
// All locations are in world by default // All locations are in world by default
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
@ -95,7 +97,7 @@ public class IslandRespawnListenerTest {
when(safeLocation.getWorld()).thenReturn(world); when(safeLocation.getWorld()).thenReturn(world);
when(im.getSafeHomeLocation(Mockito.any(), Mockito.any(), Mockito.anyInt())).thenReturn(safeLocation); when(im.getSafeHomeLocation(Mockito.any(), Mockito.any(), Mockito.anyInt())).thenReturn(safeLocation);
// Sometimes use Mockito.withSettings().verboseLogging() // Sometimes use Mockito.withSettings().verboseLogging()
User.setPlugin(plugin); User.setPlugin(plugin);
User.getInstance(player); User.getInstance(player);
} }
@ -152,7 +154,8 @@ public class IslandRespawnListenerTest {
*/ */
@Test @Test
public void testOnPlayerRespawnWrongWorld() { public void testOnPlayerRespawnWrongWorld() {
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
// Die // Die
List<ItemStack> drops = new ArrayList<>(); List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, ""); PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");

View File

@ -100,7 +100,8 @@ public class ItemFrameListenerTest {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Monsters and animals // Monsters and animals

View File

@ -106,7 +106,8 @@ public class PVPListenerTest {
User.setPlugin(plugin); User.setPlugin(plugin);
// Island World Manager // Island World Manager
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock"); when(iwm.getPermissionPrefix(Mockito.any())).thenReturn("bskyblock");
// No visitor protection right now // No visitor protection right now
when(iwm.getIvSettings(Mockito.any())).thenReturn(new ArrayList<>()); when(iwm.getIvSettings(Mockito.any())).thenReturn(new ArrayList<>());
@ -194,6 +195,11 @@ public class PVPListenerTest {
when(plugin.getNotifier()).thenReturn(notifier); when(plugin.getNotifier()).thenReturn(notifier);
} }
private void wrongWorld() {
when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
}
/** /**
* Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}. * Test method for {@link world.bentobox.bentobox.listeners.flags.PVPListener#onEntityDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
*/ */
@ -249,7 +255,7 @@ public class PVPListenerTest {
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)), new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0)))); new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
new PVPListener().onEntityDamage(e); new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
@ -282,7 +288,8 @@ public class PVPListenerTest {
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)), new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0)))); new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
new PVPListener().onEntityDamage(e); new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
@ -315,7 +322,8 @@ public class PVPListenerTest {
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)), new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0)))); new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
when(iwm.inWorld(Mockito.any())).thenReturn(false); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
new PVPListener().onEntityDamage(e); new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
@ -345,7 +353,7 @@ public class PVPListenerTest {
new PVPListener().onEntityDamage(e); new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
new PVPListener().onEntityDamage(e); new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
@ -374,7 +382,7 @@ public class PVPListenerTest {
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)), new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0)))); new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
new PVPListener().onEntityDamage(e); new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
} }
@ -548,13 +556,14 @@ public class PVPListenerTest {
Mockito.verify(hook).remove(); Mockito.verify(hook).remove();
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
pfe = new PlayerFishEvent(player, player2, hook, null); pfe = new PlayerFishEvent(player, player2, hook, null);
new PVPListener().onFishing(pfe); new PVPListener().onFishing(pfe);
assertFalse(pfe.isCancelled()); assertFalse(pfe.isCancelled());
// Correct world // Correct world
when(iwm.inWorld(Mockito.any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
// Allow PVP // Allow PVP
when(island.isAllowed(Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any())).thenReturn(true);
@ -563,7 +572,7 @@ public class PVPListenerTest {
assertFalse(pfe.isCancelled()); assertFalse(pfe.isCancelled());
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
pfe = new PlayerFishEvent(player, player2, hook, null); pfe = new PlayerFishEvent(player, player2, hook, null);
new PVPListener().onFishing(pfe); new PVPListener().onFishing(pfe);
assertFalse(pfe.isCancelled()); assertFalse(pfe.isCancelled());
@ -680,7 +689,7 @@ public class PVPListenerTest {
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference())); Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
e = new PotionSplashEvent(tp, map); e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e); new PVPListener().onSplashPotionSplash(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
@ -707,7 +716,7 @@ public class PVPListenerTest {
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
e = new PotionSplashEvent(tp, map); e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e); new PVPListener().onSplashPotionSplash(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
@ -763,7 +772,7 @@ public class PVPListenerTest {
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference())); Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
e = new PotionSplashEvent(tp, map); e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e); new PVPListener().onSplashPotionSplash(e);
assertFalse(e.isCancelled()); assertFalse(e.isCancelled());
@ -833,7 +842,7 @@ public class PVPListenerTest {
assertFalse(ae.getAffectedEntities().contains(player2)); assertFalse(ae.getAffectedEntities().contains(player2));
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference())); Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
listener.onLingeringPotionSplash(e); listener.onLingeringPotionSplash(e);
// No change to results // No change to results
assertEquals(3, ae.getAffectedEntities().size()); assertEquals(3, ae.getAffectedEntities().size());
@ -868,7 +877,7 @@ public class PVPListenerTest {
assertEquals(4, ae.getAffectedEntities().size()); assertEquals(4, ae.getAffectedEntities().size());
Mockito.verify(player, Mockito.never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference()); Mockito.verify(player, Mockito.never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
listener.onLingeringPotionSplash(e); listener.onLingeringPotionSplash(e);
assertEquals(4, ae.getAffectedEntities().size()); assertEquals(4, ae.getAffectedEntities().size());
Mockito.verify(player, Mockito.never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference()); Mockito.verify(player, Mockito.never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
@ -908,7 +917,7 @@ public class PVPListenerTest {
assertFalse(ae.getAffectedEntities().contains(player2)); assertFalse(ae.getAffectedEntities().contains(player2));
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference())); Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
listener.onLingeringPotionSplash(e); listener.onLingeringPotionSplash(e);
assertEquals(3, ae.getAffectedEntities().size()); assertEquals(3, ae.getAffectedEntities().size());
assertFalse(ae.getAffectedEntities().contains(player2)); assertFalse(ae.getAffectedEntities().contains(player2));
@ -948,7 +957,7 @@ public class PVPListenerTest {
assertFalse(ae.getAffectedEntities().contains(player2)); assertFalse(ae.getAffectedEntities().contains(player2));
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference())); Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
// Wrong world // Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false); wrongWorld();
listener.onLingeringPotionSplash(e); listener.onLingeringPotionSplash(e);
assertEquals(3, ae.getAffectedEntities().size()); assertEquals(3, ae.getAffectedEntities().size());
assertFalse(ae.getAffectedEntities().contains(player2)); assertFalse(ae.getAffectedEntities().contains(player2));

View File

@ -110,7 +110,8 @@ public class TNTListenerTest {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Monsters and animals // Monsters and animals

View File

@ -155,7 +155,8 @@ public class IslandsManagerTest {
// Worlds // Worlds
iwm = mock(IslandWorldManager.class); iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world); when(Util.getWorld(Mockito.any())).thenReturn(world);
@ -472,7 +473,8 @@ public class IslandsManagerTest {
assertEquals(Optional.empty(), im.getIslandAt(new Location(world, 100000, 120, -100000))); assertEquals(Optional.empty(), im.getIslandAt(new Location(world, 100000, 120, -100000)));
// not in world // not in world
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
assertEquals(Optional.empty(), im.getIslandAt(new Location(world, 100000, 120, -100000))); assertEquals(Optional.empty(), im.getIslandAt(new Location(world, 100000, 120, -100000)));
assertEquals(Optional.empty(), im.getIslandAt(location)); assertEquals(Optional.empty(), im.getIslandAt(location));

View File

@ -83,7 +83,8 @@ public class PlayersManagerTest {
when(nether.getName()).thenReturn("world_nether"); when(nether.getName()).thenReturn("world_nether");
end = mock(World.class); end = mock(World.class);
when(end.getName()).thenReturn("world_the_end"); when(end.getName()).thenReturn("world_the_end");
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Settings // Settings

View File

@ -52,7 +52,8 @@ public class IslandCacheTest {
// Worlds // Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class); IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
when(iwm.inWorld(any())).thenReturn(true); when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world); when(Util.getWorld(Mockito.any())).thenReturn(world);