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
*/
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
IslandWorldManager iwm = mock(IslandWorldManager.class);
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);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// We want the read tabLimit call here

View File

@ -184,7 +184,8 @@ public class CycleClickTest {
// IslandWorldManager
iwm = mock(IslandWorldManager.class);
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");
// Util
@ -195,7 +196,8 @@ public class CycleClickTest {
@Test
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");
assertTrue(udc.onClick(panel, user, ClickType.LEFT, 5));
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.wrong-world"));

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.flags.clicklisteners;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -55,7 +56,8 @@ public class IslandToggleClickTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager
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(plugin.getIWM()).thenReturn(iwm);
@ -93,7 +95,8 @@ public class IslandToggleClickTest {
@Test
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);
Mockito.verify(user).sendMessage("general.errors.wrong-world");
}

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.flags.clicklisteners;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -48,7 +49,8 @@ public class WorldToggleClickTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager
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(plugin.getIWM()).thenReturn(iwm);
@ -77,7 +79,8 @@ public class WorldToggleClickTest {
@Test
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);
Mockito.verify(user).sendMessage("general.errors.wrong-world");
}

View File

@ -52,7 +52,8 @@ public class BannedVisitorCommandsTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager
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.getVisitorBannedCommands(Mockito.any())).thenReturn(new ArrayList<>());
when(plugin.getIWM()).thenReturn(iwm);
@ -105,13 +106,15 @@ public class BannedVisitorCommandsTest {
BannedVisitorCommands bvc = new BannedVisitorCommands(plugin);
// 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);
assertFalse(e.isCancelled());
// 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
when(player.isOp()).thenReturn(true);
bvc.onVisitorCommand(e);

View File

@ -1,6 +1,7 @@
package world.bentobox.bentobox.listeners;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -41,7 +42,8 @@ public class DeathListenerTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager
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.getVisitorBannedCommands(Mockito.any())).thenReturn(new ArrayList<>());
when(plugin.getIWM()).thenReturn(iwm);
@ -53,13 +55,13 @@ public class DeathListenerTest {
when(player.getLocation()).thenReturn(mock(Location.class));
UUID uuid = UUID.randomUUID();
when(player.getUniqueId()).thenReturn(uuid);
PlayersManager pm = mock(PlayersManager.class);
when(plugin.getPlayers()).thenReturn(pm);
// Test
DeathListener dl = new DeathListener(plugin);
PlayerDeathEvent e = new PlayerDeathEvent(player, new ArrayList<>(), 0, 0, 0, 0, "died");
dl.onPlayerDeathEvent(e);
Mockito.verify(pm).addDeath(world, uuid);

View File

@ -90,7 +90,8 @@ public class NetherPortalsTest {
when(iwm.getEndWorld(Mockito.any())).thenReturn(end);
when(iwm.getIslandWorld(Mockito.any())).thenReturn(world);
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(plugin.getIWM()).thenReturn(iwm);
@ -147,6 +148,11 @@ public class NetherPortalsTest {
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)}.
*/
@ -278,7 +284,7 @@ public class NetherPortalsTest {
// Right cause, end exists, wrong world
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);
when(iwm.isEndGenerate(world)).thenReturn(true);
np.onEndIslandPortal(e);
@ -321,12 +327,13 @@ public class NetherPortalsTest {
Location from = mock(Location.class);
when(from.getWorld()).thenReturn(mock(World.class));
// Not in world
when(iwm.inWorld(any())).thenReturn(false);
wrongWorld();
EntityPortalEvent e = new EntityPortalEvent(ent, from, null, null);
np.onEntityPortal(e);
assertFalse(e.isCancelled());
// 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);
np.onEntityPortal(e);
assertTrue(e.isCancelled());
@ -353,7 +360,7 @@ public class NetherPortalsTest {
Location from = mock(Location.class);
when(from.getWorld()).thenReturn(mock(World.class));
// Not in world
when(iwm.inWorld(any())).thenReturn(false);
wrongWorld();
EntityExplodeEvent e = new EntityExplodeEvent(en, from, affectedBlocks, 0);
@ -514,7 +521,7 @@ public class NetherPortalsTest {
NetherPortals np = new NetherPortals(plugin);
Location from = mock(Location.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);
assertFalse(np.onNetherPortal(e));
}

View File

@ -117,7 +117,8 @@ public class ObsidianToLavaTest {
User.setPlugin(plugin);
// 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
when(im.userIsOnIsland(Mockito.any(), Mockito.any())).thenReturn(true);
// Set as survival
@ -165,10 +166,12 @@ public class ObsidianToLavaTest {
PlayerInteractEvent event = new PlayerInteractEvent(who, action, item, clickedBlock, BlockFace.EAST);
// 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));
// 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
for (GameMode gm : GameMode.values()) {

View File

@ -107,7 +107,8 @@ public class ChestDamageListenerTest {
// Worlds
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);
// Monsters and animals

View File

@ -60,13 +60,13 @@ public class EnderChestListenerTest {
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// World
world = mock(World.class);
// Owner
UUID uuid1 = UUID.randomUUID();
// Island initialization
Island island = mock(Island.class);
when(island.getOwner()).thenReturn(uuid1);
@ -85,7 +85,7 @@ public class EnderChestListenerTest {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// World Settings
iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
@ -94,11 +94,12 @@ public class EnderChestListenerTest {
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
// 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
Flags.ENDER_CHEST.setSetting(world, false);
// Sometimes use Mockito.withSettings().verboseLogging()
player = mock(Player.class);
UUID uuid = UUID.randomUUID();
@ -108,11 +109,11 @@ public class EnderChestListenerTest {
when(player.hasPermission(Mockito.anyString())).thenReturn(false);
when(player.getWorld()).thenReturn(world);
// Locales - this returns the string that was requested for translation
// Locales - this returns the string that was requested for translation
LocalesManager lm = mock(LocalesManager.class);
when(plugin.getLocalesManager()).thenReturn(lm);
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgumentAt(1, String.class));
}
@Test
@ -125,7 +126,7 @@ public class EnderChestListenerTest {
new EnderChestListener().onEnderChestOpen(e);
assertFalse(e.isCancelled());
}
@Test
public void testOnEnderChestOpenNotEnderChest() {
Action action = Action.RIGHT_CLICK_BLOCK;
@ -137,7 +138,7 @@ public class EnderChestListenerTest {
new EnderChestListener().onEnderChestOpen(e);
assertFalse(e.isCancelled());
}
@Test
public void testOnEnderChestOpenEnderChestNotInWorld() {
Action action = Action.RIGHT_CLICK_BLOCK;
@ -147,11 +148,12 @@ public class EnderChestListenerTest {
BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
// 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);
assertFalse(e.isCancelled());
}
@Test
public void testOnEnderChestOpenEnderChestOpPlayer() {
Action action = Action.RIGHT_CLICK_BLOCK;
@ -165,7 +167,7 @@ public class EnderChestListenerTest {
new EnderChestListener().onEnderChestOpen(e);
assertFalse(e.isCancelled());
}
@Test
public void testOnEnderChestOpenEnderChestHasBypassPerm() {
Action action = Action.RIGHT_CLICK_BLOCK;
@ -179,7 +181,7 @@ public class EnderChestListenerTest {
new EnderChestListener().onEnderChestOpen(e);
assertFalse(e.isCancelled());
}
@Test
public void testOnEnderChestOpenEnderChestOkay() {
Action action = Action.RIGHT_CLICK_BLOCK;
@ -193,7 +195,7 @@ public class EnderChestListenerTest {
new EnderChestListener().onEnderChestOpen(e);
assertFalse(e.isCancelled());
}
@Test
public void testOnEnderChestOpenEnderChestBlocked() {
Action action = Action.RIGHT_CLICK_BLOCK;
@ -227,7 +229,7 @@ public class EnderChestListenerTest {
new EnderChestListener().onCraft(e);
assertFalse(e.isCancelled());
}
@Test
public void testOnCraftEnderChest() {
Recipe recipe = mock(Recipe.class);

View File

@ -100,7 +100,8 @@ public class EndermanListenerTest {
// Worlds
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);
// Monsters and animals
@ -156,7 +157,8 @@ public class EndermanListenerTest {
*/
@Test
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();
Block to = mock(Block.class);
Material block = Material.ACACIA_DOOR;

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package world.bentobox.bentobox.listeners.flags;
@ -72,7 +72,7 @@ public class EnterExitListenerTest {
// World
World world = mock(World.class);
// Server
Server server = mock(Server.class);
PowerMockito.mockStatic(Bukkit.class);
@ -99,7 +99,7 @@ public class EnterExitListenerTest {
IslandsManager im = mock(IslandsManager.class);
when(plugin.getIslands()).thenReturn(im);
// Locales
// Locales
lm = mock(LocalesManager.class);
when(plugin.getLocalesManager()).thenReturn(lm);
when(lm.get(any(), any())).thenReturn("mock translation");
@ -147,12 +147,13 @@ public class EnterExitListenerTest {
when(im.getProtectedIslandAt(Mockito.eq(inside))).thenReturn(opIsland);
when(im.getProtectedIslandAt(Mockito.eq(inside2))).thenReturn(opIsland);
when(im.getProtectedIslandAt(Mockito.eq(outside))).thenReturn(Optional.empty());
// Island World Manager
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);
// Player's manager
PlayersManager pm = mock(PlayersManager.class);
when(pm.getName(Mockito.any())).thenReturn("tastybento");
@ -163,7 +164,7 @@ public class EnterExitListenerTest {
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// World Settings
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
@ -175,7 +176,7 @@ public class EnterExitListenerTest {
* Test method for {@link world.bentobox.bentobox.listeners.flags.EnterExitListener#onMove(org.bukkit.event.player.PlayerMoveEvent)}.
*/
@Test
public void testOnMoveInsideIsland() {
public void testOnMoveInsideIsland() {
PlayerMoveEvent e = new PlayerMoveEvent(user.getPlayer(), inside, inside);
listener.onMove(e);
// Moving in the island should result in no messages to the user
@ -186,7 +187,7 @@ public class EnterExitListenerTest {
* Test method for {@link world.bentobox.bentobox.listeners.flags.EnterExitListener#onMove(org.bukkit.event.player.PlayerMoveEvent)}.
*/
@Test
public void testOnMoveOutsideIsland() {
public void testOnMoveOutsideIsland() {
PlayerMoveEvent e = new PlayerMoveEvent(user.getPlayer(), outside, outside);
listener.onMove(e);
// Moving outside the island should result in no messages to the user
@ -206,7 +207,7 @@ public class EnterExitListenerTest {
// The island owner needs to be checked
Mockito.verify(island).getOwner();
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.EnterExitListener#onMove(org.bukkit.event.player.PlayerMoveEvent)}.
*/
@ -235,7 +236,7 @@ public class EnterExitListenerTest {
// The island owner needs to be checked
Mockito.verify(island).getOwner();
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.EnterExitListener#onMove(org.bukkit.event.player.PlayerMoveEvent)}.
*/

View File

@ -95,7 +95,8 @@ public class FireListenerTest {
// Worlds
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);
// 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.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -65,7 +66,8 @@ public class InvincibleVisitorsListenerTest {
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// Island World Manager
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(plugin.getIWM()).thenReturn(iwm);
@ -186,7 +188,8 @@ public class InvincibleVisitorsListenerTest {
@Test
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);
listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled());
@ -194,7 +197,8 @@ public class InvincibleVisitorsListenerTest {
@Test
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);
listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled());

View File

@ -1,9 +1,10 @@
/**
*
*
*/
package world.bentobox.bentobox.listeners.flags;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -76,12 +77,13 @@ public class IslandRespawnListenerTest {
// Island World Manager
iwm = mock(IslandWorldManager.class);
// 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);
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(world);
// World Settings
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
@ -94,8 +96,8 @@ public class IslandRespawnListenerTest {
safeLocation = mock(Location.class);
when(safeLocation.getWorld()).thenReturn(world);
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.getInstance(player);
}
@ -129,7 +131,7 @@ public class IslandRespawnListenerTest {
l.onPlayerRespawn(ev);
assertEquals(safeLocation, ev.getRespawnLocation());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.IslandRespawnListener#onPlayerRespawn(org.bukkit.event.player.PlayerRespawnEvent)}.
*/
@ -146,13 +148,14 @@ public class IslandRespawnListenerTest {
assertEquals(location, ev.getRespawnLocation());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.IslandRespawnListener#onPlayerRespawn(org.bukkit.event.player.PlayerRespawnEvent)}.
*/
@Test
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
List<ItemStack> drops = new ArrayList<>();
PlayerDeathEvent e = new PlayerDeathEvent(player, drops, 0, 0, 0, 0, "");
@ -167,7 +170,7 @@ public class IslandRespawnListenerTest {
l.onPlayerRespawn(ev);
assertEquals(location, ev.getRespawnLocation());
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.IslandRespawnListener#onPlayerRespawn(org.bukkit.event.player.PlayerRespawnEvent)}.
*/

View File

@ -100,7 +100,8 @@ public class ItemFrameListenerTest {
// Worlds
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);
// Monsters and animals

View File

@ -106,7 +106,8 @@ public class PVPListenerTest {
User.setPlugin(plugin);
// Island World Manager
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");
// No visitor protection right now
when(iwm.getIvSettings(Mockito.any())).thenReturn(new ArrayList<>());
@ -194,6 +195,11 @@ public class PVPListenerTest {
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)}.
*/
@ -249,7 +255,7 @@ public class PVPListenerTest {
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
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);
assertFalse(e.isCancelled());
}
@ -282,7 +288,8 @@ public class PVPListenerTest {
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
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);
assertFalse(e.isCancelled());
}
@ -315,7 +322,8 @@ public class PVPListenerTest {
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
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);
assertFalse(e.isCancelled());
}
@ -345,7 +353,7 @@ public class PVPListenerTest {
new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled());
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled());
}
@ -374,7 +382,7 @@ public class PVPListenerTest {
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
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);
assertFalse(e.isCancelled());
}
@ -548,13 +556,14 @@ public class PVPListenerTest {
Mockito.verify(hook).remove();
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
pfe = new PlayerFishEvent(player, player2, hook, null);
new PVPListener().onFishing(pfe);
assertFalse(pfe.isCancelled());
// 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
when(island.isAllowed(Mockito.any())).thenReturn(true);
@ -563,7 +572,7 @@ public class PVPListenerTest {
assertFalse(pfe.isCancelled());
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
pfe = new PlayerFishEvent(player, player2, hook, null);
new PVPListener().onFishing(pfe);
assertFalse(pfe.isCancelled());
@ -680,7 +689,7 @@ public class PVPListenerTest {
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e);
assertFalse(e.isCancelled());
@ -707,7 +716,7 @@ public class PVPListenerTest {
assertFalse(e.isCancelled());
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e);
assertFalse(e.isCancelled());
@ -763,7 +772,7 @@ public class PVPListenerTest {
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
e = new PotionSplashEvent(tp, map);
new PVPListener().onSplashPotionSplash(e);
assertFalse(e.isCancelled());
@ -833,7 +842,7 @@ public class PVPListenerTest {
assertFalse(ae.getAffectedEntities().contains(player2));
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.PVP_OVERWORLD.getHintReference()));
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
listener.onLingeringPotionSplash(e);
// No change to results
assertEquals(3, ae.getAffectedEntities().size());
@ -868,7 +877,7 @@ public class PVPListenerTest {
assertEquals(4, ae.getAffectedEntities().size());
Mockito.verify(player, Mockito.never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
listener.onLingeringPotionSplash(e);
assertEquals(4, ae.getAffectedEntities().size());
Mockito.verify(player, Mockito.never()).sendMessage(Flags.PVP_OVERWORLD.getHintReference());
@ -908,7 +917,7 @@ public class PVPListenerTest {
assertFalse(ae.getAffectedEntities().contains(player2));
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
listener.onLingeringPotionSplash(e);
assertEquals(3, ae.getAffectedEntities().size());
assertFalse(ae.getAffectedEntities().contains(player2));
@ -948,7 +957,7 @@ public class PVPListenerTest {
assertFalse(ae.getAffectedEntities().contains(player2));
Mockito.verify(notifier).notify(Mockito.any(), Mockito.eq(Flags.INVINCIBLE_VISITORS.getHintReference()));
// Wrong world
when(iwm.inWorld(Mockito.any())).thenReturn(false);
wrongWorld();
listener.onLingeringPotionSplash(e);
assertEquals(3, ae.getAffectedEntities().size());
assertFalse(ae.getAffectedEntities().contains(player2));

View File

@ -110,7 +110,8 @@ public class TNTListenerTest {
// Worlds
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);
// Monsters and animals

View File

@ -155,7 +155,8 @@ public class IslandsManagerTest {
// Worlds
iwm = mock(IslandWorldManager.class);
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);
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)));
// 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(location));

View File

@ -83,7 +83,8 @@ public class PlayersManagerTest {
when(nether.getName()).thenReturn("world_nether");
end = mock(World.class);
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);
// Settings

View File

@ -52,7 +52,8 @@ public class IslandCacheTest {
// Worlds
IslandWorldManager iwm = mock(IslandWorldManager.class);
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);
when(Util.getWorld(Mockito.any())).thenReturn(world);