From 0f5ab8ab7d691e0070f2c12098326c3c4e8b3314 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sat, 29 Sep 2018 09:01:20 -0700 Subject: [PATCH] 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. --- .../bentobox/managers/IslandWorldManager.java | 12 +++++- src/test/java/bskyblock/TestBSkyBlock.java | 3 +- .../flags/clicklisteners/CycleClickTest.java | 6 ++- .../clicklisteners/IslandToggleClickTest.java | 7 +++- .../clicklisteners/WorldToggleClickTest.java | 7 +++- .../listeners/BannedVisitorCommandsTest.java | 9 ++-- .../bentobox/listeners/DeathListenerTest.java | 10 +++-- .../bentobox/listeners/NetherPortalsTest.java | 19 ++++++--- .../listeners/ObsidianToLavaTest.java | 9 ++-- .../flags/ChestDamageListenerTest.java | 3 +- .../flags/EnderChestListenerTest.java | 36 ++++++++-------- .../listeners/flags/EndermanListenerTest.java | 6 ++- .../flags/EnterExitListenerTest.java | 23 ++++++----- .../listeners/flags/FireListenerTest.java | 3 +- .../flags/InvincibleVisitorsListenerTest.java | 10 +++-- .../flags/IslandRespawnListenerTest.java | 21 ++++++---- .../flags/ItemFrameListenerTest.java | 3 +- .../listeners/flags/PVPListenerTest.java | 41 +++++++++++-------- .../listeners/flags/TNTListenerTest.java | 3 +- .../bentobox/managers/IslandsManagerTest.java | 6 ++- .../bentobox/managers/PlayersManagerTest.java | 3 +- .../managers/island/IslandCacheTest.java | 3 +- 22 files changed, 153 insertions(+), 90 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandWorldManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandWorldManager.java index cad78aada..26ad4f380 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandWorldManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandWorldManager.java @@ -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)); } /** diff --git a/src/test/java/bskyblock/TestBSkyBlock.java b/src/test/java/bskyblock/TestBSkyBlock.java index fa37374ba..dd736c48a 100644 --- a/src/test/java/bskyblock/TestBSkyBlock.java +++ b/src/test/java/bskyblock/TestBSkyBlock.java @@ -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 diff --git a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/CycleClickTest.java b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/CycleClickTest.java index 3e72c02c9..ae986dd1d 100644 --- a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/CycleClickTest.java +++ b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/CycleClickTest.java @@ -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")); diff --git a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClickTest.java b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClickTest.java index 7e5e9a727..342d07f6c 100644 --- a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClickTest.java +++ b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClickTest.java @@ -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"); } diff --git a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClickTest.java b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClickTest.java index fc191096b..24505afbd 100644 --- a/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClickTest.java +++ b/src/test/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClickTest.java @@ -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"); } diff --git a/src/test/java/world/bentobox/bentobox/listeners/BannedVisitorCommandsTest.java b/src/test/java/world/bentobox/bentobox/listeners/BannedVisitorCommandsTest.java index 147798b5f..665f61aab 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/BannedVisitorCommandsTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/BannedVisitorCommandsTest.java @@ -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); diff --git a/src/test/java/world/bentobox/bentobox/listeners/DeathListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/DeathListenerTest.java index dbacfbc54..d2ab5305b 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/DeathListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/DeathListenerTest.java @@ -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); diff --git a/src/test/java/world/bentobox/bentobox/listeners/NetherPortalsTest.java b/src/test/java/world/bentobox/bentobox/listeners/NetherPortalsTest.java index d502e677d..8fc7e523f 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/NetherPortalsTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/NetherPortalsTest.java @@ -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)); } diff --git a/src/test/java/world/bentobox/bentobox/listeners/ObsidianToLavaTest.java b/src/test/java/world/bentobox/bentobox/listeners/ObsidianToLavaTest.java index 2c547327a..b8933c1a9 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/ObsidianToLavaTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/ObsidianToLavaTest.java @@ -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()) { diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/ChestDamageListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/ChestDamageListenerTest.java index 44445ccca..6e5ed7925 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/ChestDamageListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/ChestDamageListenerTest.java @@ -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 diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/EnderChestListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/EnderChestListenerTest.java index c5be271f0..0881e12f3 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/EnderChestListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/EnderChestListenerTest.java @@ -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 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) 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); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/EndermanListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/EndermanListenerTest.java index 14a055070..27cd2dff3 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/EndermanListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/EndermanListenerTest.java @@ -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; diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/EnterExitListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/EnterExitListenerTest.java index 927be0262..ebad42bc4 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/EnterExitListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/EnterExitListenerTest.java @@ -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)}. */ diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/FireListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/FireListenerTest.java index 91b08bc8f..425d225a5 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/FireListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/FireListenerTest.java @@ -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 diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/InvincibleVisitorsListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/InvincibleVisitorsListenerTest.java index 36e35deb9..1f52af345 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/InvincibleVisitorsListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/InvincibleVisitorsListenerTest.java @@ -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()); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/IslandRespawnListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/IslandRespawnListenerTest.java index 40778986b..0f8799b5c 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/IslandRespawnListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/IslandRespawnListenerTest.java @@ -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 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)}. */ diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/ItemFrameListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/ItemFrameListenerTest.java index b1fdabd18..f75a067ca 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/ItemFrameListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/ItemFrameListenerTest.java @@ -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 diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/PVPListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/PVPListenerTest.java index 5b69b9a74..cec3a350f 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/PVPListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/PVPListenerTest.java @@ -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>(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>(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>(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>(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)); diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/TNTListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/TNTListenerTest.java index 04597c04c..8531f5287 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/TNTListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/TNTListenerTest.java @@ -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 diff --git a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java index 6f6116a24..3cc46e795 100644 --- a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java @@ -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)); diff --git a/src/test/java/world/bentobox/bentobox/managers/PlayersManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/PlayersManagerTest.java index 6a0737525..a085e544d 100644 --- a/src/test/java/world/bentobox/bentobox/managers/PlayersManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/PlayersManagerTest.java @@ -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 diff --git a/src/test/java/world/bentobox/bentobox/managers/island/IslandCacheTest.java b/src/test/java/world/bentobox/bentobox/managers/island/IslandCacheTest.java index a0bdee374..ca055485d 100644 --- a/src/test/java/world/bentobox/bentobox/managers/island/IslandCacheTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/island/IslandCacheTest.java @@ -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);