From efb2adb455187cdfe1919afef2ad67b3ea7d62b9 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Wed, 1 Aug 2018 11:02:13 +0200 Subject: [PATCH] Removed commands test units --- .../admin/AdminClearResetsAllCommandTest.java | 119 ------ .../admin/AdminClearResetsCommandTest.java | 169 -------- .../commands/admin/AdminInfoCommandTest.java | 214 ---------- .../admin/AdminRegisterCommandTest.java | 220 ---------- .../admin/AdminUnregisterCommandTest.java | 190 --------- .../admin/range/AdminRangeCommandTest.java | 141 ------- .../range/AdminRangeDisplayCommandTest.java | 171 -------- .../range/AdminRangeResetCommandTest.java | 202 --------- .../admin/range/AdminRangeSetCommandTest.java | 291 ------------- .../admin/team/AdminTeamAddCommandTest.java | 303 -------------- .../team/AdminTeamDisbandCommandTest.java | 200 --------- .../admin/team/AdminTeamKickCommandTest.java | 198 --------- .../team/AdminTeamMakeLeaderCommandTest.java | 201 --------- .../commands/island/IslandBanCommandTest.java | 391 ------------------ .../island/IslandBanlistCommandTest.java | 173 -------- .../commands/island/IslandGoCommandTest.java | 198 --------- .../island/IslandResetCommandTest.java | 322 --------------- .../island/IslandUnbanCommandTest.java | 253 ------------ .../team/IslandTeamInviteCommandTest.java | 213 ---------- .../team/IslandTeamKickCommandTest.java | 268 ------------ .../team/IslandTeamLeaveCommandTest.java | 193 --------- 21 files changed, 4630 deletions(-) delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/AdminClearResetsAllCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/AdminClearResetsCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/AdminInfoCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/AdminRegisterCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/AdminUnregisterCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeDisplayCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeResetCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeSetCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamAddCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamDisbandCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamKickCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamMakeLeaderCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/island/IslandBanCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/island/IslandBanlistCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/island/IslandGoCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/island/IslandResetCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/island/IslandUnbanCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamInviteCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamKickCommandTest.java delete mode 100644 src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamLeaveCommandTest.java diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/AdminClearResetsAllCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/AdminClearResetsAllCommandTest.java deleted file mode 100644 index e2239ae37..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/AdminClearResetsAllCommandTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package world.bentobox.bentobox.commands.admin; - -import static org.junit.Assert.assertFalse; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminClearResetsAllCommandTest { - - private CompositeCommand ac; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - UUID uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminClearResetsAllCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteCheckConfirm() { - AdminClearResetsAllCommand itl = new AdminClearResetsAllCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.any()); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/AdminClearResetsCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/AdminClearResetsCommandTest.java deleted file mode 100644 index 2d86a0359..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/AdminClearResetsCommandTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.admin; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author ben - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminClearResetsCommandTest { - - private CompositeCommand ac; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - UUID uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminClearResetsCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoTarget() { - AdminClearResetsCommand itl = new AdminClearResetsCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Show help - Mockito.verify(user).sendMessage(Mockito.eq("commands.help.header"), Mockito.eq("[label]"), Mockito.any()); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminClearResetsCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminClearResetsCommand itl = new AdminClearResetsCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminClearResetsCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecutePlayerNoIsland() { - AdminClearResetsCommand itl = new AdminClearResetsCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-no-island")); - } - - /** - * Test method for {@link us.AdminClearResetsCommand.tastybento.bskyblock.commands.admin.AdminClearResetCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteSuccess() { - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - AdminClearResetsCommand itl = new AdminClearResetsCommand(ac); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - // Add other verifications - Mockito.verify(user).sendMessage("commands.admin.clearresets.cleared"); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/AdminInfoCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/AdminInfoCommandTest.java deleted file mode 100644 index fc0302954..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/AdminInfoCommandTest.java +++ /dev/null @@ -1,214 +0,0 @@ -package world.bentobox.bentobox.commands.admin; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminInfoCommandTest { - - private BentoBox plugin; - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - - /** - * Test method for {@link AdminInfoCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteNoTargetConsole() { - AdminInfoCommand itl = new AdminInfoCommand(ac); - CommandSender sender = mock(CommandSender.class); - User console = User.getInstance(sender); - assertFalse(itl.execute(console, itl.getLabel(), new ArrayList<>())); - // Show help - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminInfoCommand#execute(User, String, List)} . - */ - @Test - public void testExecuteUnknownPlayer() { - AdminInfoCommand itl = new AdminInfoCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminInfoCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecutePlayerHasNoIsland() { - AdminInfoCommand itl = new AdminInfoCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-no-island")); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminInfoCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteSuccess() { - AdminInfoCommand itl = new AdminInfoCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - Island is = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.eq(notUUID))).thenReturn(is); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(is).showInfo(Mockito.eq(plugin), Mockito.eq(user), Mockito.any()); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminInfoCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteUserNotOnIsland() { - when(user.isPlayer()).thenReturn(true); - AdminInfoCommand itl = new AdminInfoCommand(ac); - // No island here - when(im.getIslandAt(Mockito.any())).thenReturn(Optional.empty()); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Confirm other verifications - Mockito.verify(user).sendMessage("commands.admin.info.no-island"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.AdminInfoCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteSuccessUserOnIsland() { - when(user.isPlayer()).thenReturn(true); - AdminInfoCommand itl = new AdminInfoCommand(ac); - Location loc = mock(Location.class); - - // Island has owner - Island is = mock(Island.class); - when(is.getOwner()).thenReturn(uuid); - when(is.showInfo(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true); - Optional opi = Optional.of(is); - when(im.getIslandAt(Mockito.any())).thenReturn(opi); - when(user.getLocation()).thenReturn(loc); - - - assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Confirm other verifications - Mockito.verify(is).showInfo(Mockito.eq(plugin), Mockito.eq(user), Mockito.any()); - } -} \ No newline at end of file diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/AdminRegisterCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/AdminRegisterCommandTest.java deleted file mode 100644 index 70051879b..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/AdminRegisterCommandTest.java +++ /dev/null @@ -1,220 +0,0 @@ -package world.bentobox.bentobox.commands.admin; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Optional; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.util.Vector; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminRegisterCommandTest { - - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminRegisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoTarget() { - AdminRegisterCommand itl = new AdminRegisterCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Show help - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminRegisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminRegisterCommand itl = new AdminRegisterCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminRegisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecutePlayerHasIsland() { - AdminRegisterCommand itl = new AdminRegisterCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-island")); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminRegisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteInTeam() { - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - AdminRegisterCommand itl = new AdminRegisterCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("commands.admin.register.cannot-register-team-player"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminRegisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteAlreadyOwnedIsland() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - Location loc = mock(Location.class); - - // Island has owner - Island is = mock(Island.class); - when(is.getOwner()).thenReturn(uuid); - Optional opi = Optional.of(is); - when(im.getIslandAt(Mockito.any())).thenReturn(opi); - when(user.getLocation()).thenReturn(loc); - AdminRegisterCommand itl = new AdminRegisterCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("commands.admin.register.already-owned"); - } - - /** - * Test method for {@link us.world.bentobox.bbox.commands.admin.teams.AdminRegisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteSuccess() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - Island is = mock(Island.class); - Location loc = mock(Location.class); - when(loc.toVector()).thenReturn(new Vector(123,123,432)); - when(is.getCenter()).thenReturn(loc); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - Optional opi = Optional.of(is); - when(im.getIslandAt(Mockito.any())).thenReturn(opi); - when(user.getLocation()).thenReturn(loc); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - AdminRegisterCommand itl = new AdminRegisterCommand(ac); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - // Add other verifications - Mockito.verify(user).sendMessage("commands.admin.register.registered-island", "[xyz]", "123,123,432"); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/AdminUnregisterCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/AdminUnregisterCommandTest.java deleted file mode 100644 index 7b1f98b38..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/AdminUnregisterCommandTest.java +++ /dev/null @@ -1,190 +0,0 @@ -package world.bentobox.bentobox.commands.admin; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.util.Vector; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminUnregisterCommandTest { - - private CompositeCommand ac; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - UUID uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminUnregisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoTarget() { - AdminUnregisterCommand itl = new AdminUnregisterCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Show help - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminUnregisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminUnregisterCommand itl = new AdminUnregisterCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminUnregisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecutePlayerNoIsland() { - AdminUnregisterCommand itl = new AdminUnregisterCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-no-island")); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminUnregisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteInTeam() { - when(im.inTeam(Mockito.any(),Mockito.any())).thenReturn(true); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - AdminUnregisterCommand itl = new AdminUnregisterCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("commands.admin.unregister.cannot-unregister-team-player"); - } - - /** - * Test method for {@link us.world.bentobox.bbox.commands.admin.teams.AdminUnregisterCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteSuccess() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false); - Island is = mock(Island.class); - Location loc = mock(Location.class); - when(loc.toVector()).thenReturn(new Vector(123,123,432)); - when(is.getCenter()).thenReturn(loc); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - AdminUnregisterCommand itl = new AdminUnregisterCommand(ac); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - // Add other verifications - Mockito.verify(user).sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", "123,123,432"); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeCommandTest.java deleted file mode 100644 index ad7477125..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeCommandTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package world.bentobox.bentobox.commands.admin.range; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminRangeCommandTest { - - private BentoBox plugin; - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - Answer answer = new Answer() { - - @Override - public String answer(InvocationOnMock invocation) throws Throwable { - return invocation.getArgumentAt(1, String.class); - }}; - when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer ); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - - @Test - public void testExecuteConsoleNoArgs() { - AdminRangeCommand arc = new AdminRangeCommand(ac); - CommandSender sender = mock(CommandSender.class); - User console = User.getInstance(sender); - arc.execute(console, "", new ArrayList<>()); - // Show help - Mockito.verify(sender).sendMessage("commands.help.header"); - } - - @Test - public void testExecutePlayerNoArgs() { - AdminRangeCommand arc = new AdminRangeCommand(ac); - arc.execute(user, "", new ArrayList<>()); - // Show help" - Mockito.verify(user).sendMessage("commands.help.header","[label]","BSkyBlock"); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeDisplayCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeDisplayCommandTest.java deleted file mode 100644 index 6c4e52439..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeDisplayCommandTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.admin.range; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminRangeDisplayCommandTest { - - private BentoBox plugin; - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - Answer answer = new Answer() { - - @Override - public String answer(InvocationOnMock invocation) throws Throwable { - return invocation.getArgumentAt(1, String.class); - }}; - when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer ); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeDisplayCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecutePlayerDisplayArgs() { - AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac); - ardc.execute(user, "display", new ArrayList<>()); - // Show display - Mockito.verify(user).sendMessage("commands.admin.range.display.showing"); - Mockito.verify(user).sendMessage("commands.admin.range.display.hint"); - // Run command again - ardc.execute(user, "display", new ArrayList<>()); - // Remove - Mockito.verify(user).sendMessage("commands.admin.range.display.hiding"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeDisplayCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecutePlayeShowArgs() { - AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac); - ardc.execute(user, "show", new ArrayList<>()); - // Show display - Mockito.verify(user).sendMessage("commands.admin.range.display.showing"); - Mockito.verify(user).sendMessage("commands.admin.range.display.hint"); - // Run command again - ardc.execute(user, "show", new ArrayList<>()); - Mockito.verify(user).sendMessage("commands.admin.range.display.already-on"); - ardc.execute(user, "hide", new ArrayList<>()); - Mockito.verify(user).sendMessage("commands.admin.range.display.hiding"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeDisplayCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecutePlayeHideArgs() { - AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac); - ardc.execute(user, "hide", new ArrayList<>()); - Mockito.verify(user).sendMessage("commands.admin.range.display.already-off"); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeResetCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeResetCommandTest.java deleted file mode 100644 index 6f73a3202..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeResetCommandTest.java +++ /dev/null @@ -1,202 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.admin.range; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.localization.TextVariables; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminRangeResetCommandTest { - - private BentoBox plugin; - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(iwm.getIslandProtectionRange(Mockito.any())).thenReturn(200); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - Island island = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - Answer answer = new Answer() { - - @Override - public String answer(InvocationOnMock invocation) throws Throwable { - return invocation.getArgumentAt(1, String.class); - } - }; - - when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer ); - when(plugin.getLocalesManager()).thenReturn(lm); - - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeResetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteConsoleNoArgs() { - AdminRangeResetCommand arc = new AdminRangeResetCommand(ac); - CommandSender sender = mock(CommandSender.class); - User console = User.getInstance(sender); - arc.execute(console, "", new ArrayList<>()); - // Show help - Mockito.verify(sender).sendMessage("commands.help.header"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeResetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecutePlayerNoArgs() { - AdminRangeResetCommand arc = new AdminRangeResetCommand(ac); - arc.execute(user, "", new ArrayList<>()); - // Show help - Mockito.verify(user).sendMessage("commands.help.header","[label]","BSkyBlock"); - } - - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeResetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminRangeResetCommand arc = new AdminRangeResetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("general.errors.unknown-player"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeResetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteKnownPlayerNoIsland() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - AdminRangeResetCommand arc = new AdminRangeResetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("general.errors.player-has-no-island"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeResetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteKnownPlayer() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - AdminRangeResetCommand arc = new AdminRangeResetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("commands.admin.range.reset.success", TextVariables.NUMBER, "200"); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeSetCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeSetCommandTest.java deleted file mode 100644 index 0a3ee3a8c..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/range/AdminRangeSetCommandTest.java +++ /dev/null @@ -1,291 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.admin.range; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.localization.TextVariables; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminRangeSetCommandTest { - - private BentoBox plugin; - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(iwm.getIslandProtectionRange(Mockito.any())).thenReturn(200); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - Island island = mock(Island.class); - when(island.getRange()).thenReturn(50); - when(island.getProtectionRange()).thenReturn(50); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - Answer answer = new Answer() { - - @Override - public String answer(InvocationOnMock invocation) throws Throwable { - return invocation.getArgumentAt(1, String.class); - } - }; - - when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer ); - when(plugin.getLocalesManager()).thenReturn(lm); - - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteConsoleNoArgs() { - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - CommandSender sender = mock(CommandSender.class); - User console = User.getInstance(sender); - arc.execute(console, "", new ArrayList<>()); - // Show help - Mockito.verify(sender).sendMessage("commands.help.header"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecutePlayerNoArgs() { - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - arc.execute(user, "", new ArrayList<>()); - // Show help - Mockito.verify(user).sendMessage("commands.help.header","[label]","BSkyBlock"); - } - - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("100"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("general.errors.unknown-player"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteKnownPlayerNoIsland() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("100"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("general.errors.player-has-no-island"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteTooHigh() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("100"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.too-high", TextVariables.NUMBER, "50"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteNotANumber() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("NAN"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, "NAN"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteDoubleNumber() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("3.141592654"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, "3.141592654"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteZero() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("0"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.too-low", TextVariables.NUMBER, "0"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteNegNumber() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("-437645"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, "-437645"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecuteSame() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("50"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.same-as-before", TextVariables.NUMBER, "50"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.range.AdminRangeSetCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}. - */ - @Test - public void testExecute() { - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - AdminRangeSetCommand arc = new AdminRangeSetCommand(ac); - List args = new ArrayList<>(); - args.add("tastybento"); - args.add("48"); - arc.execute(user, "", args); - Mockito.verify(user).sendMessage("commands.admin.range.set.success", TextVariables.NUMBER, "48"); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamAddCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamAddCommandTest.java deleted file mode 100644 index 991fcaa31..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamAddCommandTest.java +++ /dev/null @@ -1,303 +0,0 @@ -package world.bentobox.bentobox.commands.admin.team; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminTeamAddCommandTest { - - private BentoBox plugin; - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - when(ac.getTopLabel()).thenReturn("bsb"); - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - } - - - /** - * Test method for {@link AdminTeamAddCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteWrongArgs() { - AdminTeamAddCommand itl = new AdminTeamAddCommand(ac); - List args = new ArrayList<>(); - assertFalse(itl.execute(user, itl.getLabel(), args)); - // Show help - args.add("arg1"); - assertFalse(itl.execute(user, itl.getLabel(), args)); - // Show help - args.add("args2"); - args.add("args3"); - assertFalse(itl.execute(user, itl.getLabel(), args)); - // Show help - } - - /** - * Test method for {@link AdminTeamAddCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminTeamAddCommand itl = new AdminTeamAddCommand(ac); - String[] name = {"tastybento", "poslovich"}; - - // Unknown leader - when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(null); - when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID); - assertFalse(itl.execute(user, ac.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("general.errors.unknown-player-name", "[name]", "tastybento"); - - // Unknown target - when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid); - when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(null); - assertFalse(itl.execute(user, ac.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("general.errors.unknown-player-name", "[name]", "poslovich"); - } - - /** - * Test method for {@link AdminTeamAddCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteTargetTargetInTeam() { - AdminTeamAddCommand itl = new AdminTeamAddCommand(ac); - String[] name = {"tastybento", "poslovich"}; - - when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid); - when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID); - - when(im.inTeam(Mockito.any(), Mockito.eq(notUUID))).thenReturn(true); - - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.errors.already-on-team")); - } - - - /** - * Test method for {@link AdminTeamAddCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteAddNoIsland() { - AdminTeamAddCommand itl = new AdminTeamAddCommand(ac); - String[] name = {"tastybento", "poslovich"}; - - when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid); - when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID); - - // No island, - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("general.errors.player-has-no-island"); - - } - - /** - * Test method for {@link AdminTeamAddCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteAddNotLeader() { - AdminTeamAddCommand itl = new AdminTeamAddCommand(ac); - String[] name = {"tastybento", "poslovich"}; - - when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid); - when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID); - - // Has island, has team, but not a leader - when(im.hasIsland(Mockito.any(),Mockito.eq(uuid))).thenReturn(true); - when(im.inTeam(Mockito.any(),Mockito.eq(uuid))).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.eq(uuid))).thenReturn(notUUID); - - // Island - Island island = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(island); - - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("commands.admin.team.add.name-not-leader", "[name]", "tastybento"); - Mockito.verify(island).showMembers(Mockito.eq(plugin), Mockito.any(), Mockito.any()); - } - - /** - * Test method for {@link AdminTeamAddCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteAddTargetHasIsland() { - AdminTeamAddCommand itl = new AdminTeamAddCommand(ac); - String[] name = {"tastybento", "poslovich"}; - - when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid); - when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID); - - // Has island, has team, is leader - when(im.hasIsland(Mockito.any(),Mockito.eq(uuid))).thenReturn(true); - when(im.inTeam(Mockito.any(),Mockito.eq(uuid))).thenReturn(true); - when(im.getTeamLeader(Mockito.any(), Mockito.eq(uuid))).thenReturn(uuid); - - // Target has island - when(im.hasIsland(Mockito.any(), Mockito.eq(notUUID))).thenReturn(true); - - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("commands.admin.team.add.name-has-island", "[name]", "poslovich"); - - } - - /** - * Test method for {@link AdminTeamAddCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteAddTargetHasIslandNoTeam() { - AdminTeamAddCommand itl = new AdminTeamAddCommand(ac); - String[] name = {"tastybento", "poslovich"}; - - when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid); - when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID); - - // Has island, no team - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - - // Target has island - when(im.hasIsland(Mockito.any(), Mockito.eq(notUUID))).thenReturn(true); - - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("commands.admin.team.add.name-has-island", "[name]", "poslovich"); - - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminTeamAddCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteSuccess() { - AdminTeamAddCommand itl = new AdminTeamAddCommand(ac); - String[] name = {"tastybento", "poslovich"}; - - when(pm.getUUID(Mockito.eq("tastybento"))).thenReturn(uuid); - when(pm.getUUID(Mockito.eq("poslovich"))).thenReturn(notUUID); - - // Has island, no team - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - - // Target has no island - when(im.hasIsland(Mockito.any(), Mockito.eq(notUUID))).thenReturn(false); - - // Island - Island island = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(island); - - // Player name - when(pm.getName(Mockito.eq(uuid))).thenReturn("tastybento"); - when(pm.getName(Mockito.eq(notUUID))).thenReturn("poslovich"); - when(plugin.getPlayers()).thenReturn(pm); - - // Success - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(island).addMember(notUUID); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamDisbandCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamDisbandCommandTest.java deleted file mode 100644 index ab7b88a2d..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamDisbandCommandTest.java +++ /dev/null @@ -1,200 +0,0 @@ -package world.bentobox.bentobox.commands.admin.team; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminTeamDisbandCommandTest { - - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - - /** - * Test method for {@link AdminTeamDisbandCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteNoTarget() { - AdminTeamDisbandCommand itl = new AdminTeamDisbandCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - } - - /** - * Test method for {@link AdminTeamDisbandCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminTeamDisbandCommand itl = new AdminTeamDisbandCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - /** - * Test method for {@link AdminTeamDisbandCommand#execute(User, String, List)}. - */ - @Test - public void testExecutePlayerNotInTeam() { - AdminTeamDisbandCommand itl = new AdminTeamDisbandCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(new HashSet<>()); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-in-team")); - } - - /** - * Test method for {@link AdminTeamDisbandCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteDisbandNotLeader() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); - Island is = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - when(im.getTeamLeader(Mockito.any(), Mockito.eq(notUUID))).thenReturn(uuid); - when(pm.getName(Mockito.any())).thenReturn("leader"); - - AdminTeamDisbandCommand itl = new AdminTeamDisbandCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("commands.admin.team.disband.use-disband-leader", "[leader]", "leader"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminTeamDisbandCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteSuccess() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); - Island is = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - // Leader - when(im.getTeamLeader(Mockito.any(), Mockito.eq(notUUID))).thenReturn(notUUID); - // Members - Set members = new HashSet<>(); - members.add(uuid); - members.add(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members); - - AdminTeamDisbandCommand itl = new AdminTeamDisbandCommand(ac); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(im, Mockito.never()).setLeaveTeam(Mockito.any(), Mockito.eq(notUUID)); - Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid)); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamKickCommandTest.java deleted file mode 100644 index aed7ee8ad..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamKickCommandTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.admin.team; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminTeamKickCommandTest { - - private BentoBox plugin; - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - - /** - * Test method for {@link AdminTeamKickCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteNoTarget() { - AdminTeamKickCommand itl = new AdminTeamKickCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Show help - } - - /** - * Test method for {@link AdminTeamKickCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminTeamKickCommand itl = new AdminTeamKickCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - /** - * Test method for {@link AdminTeamKickCommand#execute(User, String, List)}. - */ - @Test - public void testExecutePlayerNotInTeam() { - AdminTeamKickCommand itl = new AdminTeamKickCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(new HashSet<>()); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-in-team")); - } - - /** - * Test method for {@link AdminTeamKickCommand#execute(User, String, List)} . - */ - @Test - public void testExecuteKickLeader() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); - Island is = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - when(im.getTeamLeader(Mockito.any(), Mockito.eq(notUUID))).thenReturn(notUUID); - - AdminTeamKickCommand itl = new AdminTeamKickCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.team.kick.cannot-kick-leader")); - Mockito.verify(is).showMembers(Mockito.any(), Mockito.any(), Mockito.any()); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminTeamKickCommand#execute(User, String, List)}. - */ - @Test - public void testExecute() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); - Island is = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - when(im.getTeamLeader(Mockito.any(), Mockito.eq(notUUID))).thenReturn(uuid); - - AdminTeamKickCommand itl = new AdminTeamKickCommand(ac); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID)); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamMakeLeaderCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamMakeLeaderCommandTest.java deleted file mode 100644 index 576cb0716..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/admin/team/AdminTeamMakeLeaderCommandTest.java +++ /dev/null @@ -1,201 +0,0 @@ -package world.bentobox.bentobox.commands.admin.team; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class AdminTeamMakeLeaderCommandTest { - - private CompositeCommand ac; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ac = mock(CompositeCommand.class); - when(ac.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Island World Manager - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true); - when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - } - - - /** - * Test method for {@link AdminTeamMakeLeaderCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteNoTarget() { - AdminTeamMakeLeaderCommand itl = new AdminTeamMakeLeaderCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Show help - } - - /** - * Test method for {@link AdminTeamMakeLeaderCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - AdminTeamMakeLeaderCommand itl = new AdminTeamMakeLeaderCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - /** - * Test method for {@link AdminTeamMakeLeaderCommand#execute(User, String, List)}. - */ - @Test - public void testExecutePlayerNotInTeam() { - AdminTeamMakeLeaderCommand itl = new AdminTeamMakeLeaderCommand(ac); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(new HashSet<>()); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-in-team")); - } - - /** - * Test method for {@link AdminTeamMakeLeaderCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteMakeLeaderAlreadyLeader() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); - Island is = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - when(im.getTeamLeader(Mockito.any(), Mockito.eq(notUUID))).thenReturn(notUUID); - - AdminTeamMakeLeaderCommand itl = new AdminTeamMakeLeaderCommand(ac); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage("commands.admin.team.makeleader.already-leader"); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.admin.team.AdminTeamMakeLeaderCommand#execute(User, String, List)}. - */ - @Test - public void testExecuteSuccess() { - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); - Island is = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - // Leader - when(im.getTeamLeader(Mockito.any(), Mockito.eq(notUUID))).thenReturn(uuid); - when(pm.getName(Mockito.eq(uuid))).thenReturn("leader"); - // Members - Set members = new HashSet<>(); - members.add(uuid); - members.add(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members); - - AdminTeamMakeLeaderCommand itl = new AdminTeamMakeLeaderCommand(ac); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - // Add other verifications - Mockito.verify(im).makeLeader(Mockito.any(), Mockito.eq(user), Mockito.eq(notUUID), Mockito.any()); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/island/IslandBanCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/island/IslandBanCommandTest.java deleted file mode 100644 index 1720f56d5..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/island/IslandBanCommandTest.java +++ /dev/null @@ -1,391 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.island; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.localization.TextVariables; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class IslandBanCommandTest { - - private CompositeCommand ic; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private Island island; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - - // Parent command has no aliases - ic = mock(CompositeCommand.class); - when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // No island for player to begin with (set it later in the tests) - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Island Banned list initialization - island = mock(Island.class); - when(island.getBanned()).thenReturn(new HashSet<>()); - when(island.isBanned(Mockito.any())).thenReturn(false); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - - // IWM friendly name - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandBanCommand#execute(User, String, List)}. - */ - // Island ban command by itself - - // *** Error conditions *** - // Ban without an island - // Ban as not a team leader - // Ban unknown user - // Ban self - // Ban team mate - // Ban someone you have already banned - // Ban an Op - - // *** Working conditions *** - // Ban offline user - // Ban online user - - @Test - public void testNoArgs() { - IslandBanCommand ibc = new IslandBanCommand(ic); - assertFalse(ibc.execute(user, ibc.getLabel(), new ArrayList<>())); - } - - @Test - public void testNoIsland() { - IslandBanCommand ibc = new IslandBanCommand(ic); - assertFalse(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.errors.no-island"); - } - - @Test - public void testNotOwner() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - assertFalse(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.errors.not-leader"); - } - - @Test - public void testUnknownUser() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(pm.getUUID(Mockito.anyString())).thenReturn(null); - assertFalse(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.errors.unknown-player"); - } - - @Test - public void testBanSelf() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - assertFalse(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("commands.island.ban.cannot-ban-yourself"); - } - - @Test - public void testBanTeamMate() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID teamMate = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(teamMate); - Set members = new HashSet<>(); - members.add(uuid); - members.add(teamMate); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members); - assertFalse(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("commands.island.ban.cannot-ban-member"); - } - - @Test - public void testBanAlreadyBanned() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID bannedUser = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(bannedUser); - when(island.isBanned(Mockito.eq(bannedUser))).thenReturn(true); - assertFalse(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("commands.island.ban.player-already-banned"); - } - - @Test - public void testBanOp() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID op = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(op); - PowerMockito.mockStatic(User.class); - User opUser = mock(User.class); - when(opUser.isOp()).thenReturn(true); - when(opUser.isPlayer()).thenReturn(true); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(opUser); - assertFalse(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("commands.island.ban.cannot-ban"); - } - - @Test - public void testBanOfflineUser() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID targetUuid = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(targetUuid); - PowerMockito.mockStatic(User.class); - User targetUser = mock(User.class); - when(targetUser.isOp()).thenReturn(false); - when(targetUser.isPlayer()).thenReturn(true); - when(targetUser.isOnline()).thenReturn(false); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser); - - // Allow adding to ban list - when(island.addToBanList(Mockito.any())).thenReturn(true); - - assertTrue(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.success"); - Mockito.verify(targetUser).sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName()); - } - - @Test - public void testBanOnlineUser() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID op = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(op); - PowerMockito.mockStatic(User.class); - User targetUser = mock(User.class); - when(targetUser.isOp()).thenReturn(false); - when(targetUser.isPlayer()).thenReturn(true); - when(targetUser.isOnline()).thenReturn(true); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser); - // Allow adding to ban list - when(island.addToBanList(Mockito.any())).thenReturn(true); - - assertTrue(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.success"); - Mockito.verify(targetUser).sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName()); - } - - @Test - public void testCancelledBan() { - IslandBanCommand ibc = new IslandBanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID op = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(op); - PowerMockito.mockStatic(User.class); - User targetUser = mock(User.class); - when(targetUser.isOp()).thenReturn(false); - when(targetUser.isPlayer()).thenReturn(true); - when(targetUser.isOnline()).thenReturn(true); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser); - // Disallow adding to ban list - even cancelled - when(island.addToBanList(Mockito.any())).thenReturn(false); - - assertFalse(ibc.execute(user, ibc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user, Mockito.never()).sendMessage("general.success"); - Mockito.verify(targetUser, Mockito.never()).sendMessage("commands.island.ban.owner-banned-you", "[owner]", user.getName()); - } - - @Test - public void testTabComplete() { - - String[] names = {"adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry", "ian", "joe"}; - Map online = new HashMap<>(); - - Set banned = new HashSet<>(); - Set onlinePlayers = new HashSet<>(); - for (int j = 0; j < names.length; j++) { - Player p = mock(Player.class); - UUID uuid = UUID.randomUUID(); - when(p.getUniqueId()).thenReturn(uuid); - when(p.getName()).thenReturn(names[j]); - online.put(uuid, names[j]); - // Ban the first 3 players - if (j < 3) { - banned.add(uuid); - } - onlinePlayers.add(p); - } - - when(island.isBanned(Mockito.any(UUID.class))).thenAnswer(new Answer() { - - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - return banned.contains(invocation.getArgumentAt(0, UUID.class)); - } - - }); - // Create the names - when(pm.getName(Mockito.any(UUID.class))).then(new Answer() { - - @Override - public String answer(InvocationOnMock invocation) throws Throwable { - return online.getOrDefault(invocation.getArgumentAt(0, UUID.class), "tastybento"); - } - - }); - - // Return a set of online players - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getOnlinePlayers()).then(new Answer>() { - - @Override - public Set answer(InvocationOnMock invocation) throws Throwable { - return onlinePlayers; - } - - }); - - IslandBanCommand ibc = new IslandBanCommand(ic); - // Set up the user - User user = mock(User.class); - when(user.getUniqueId()).thenReturn(UUID.randomUUID()); - Player player = mock(Player.class); - // Player can see every other player except Ian - when(player.canSee(Mockito.any(Player.class))).thenAnswer(new Answer() { - - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - Player p = invocation.getArgumentAt(0, Player.class); - return !p.getName().equals("ian"); - } - - }); - when(user.getPlayer()).thenReturn(player); - - // Get the tab-complete list with no argument - Optional> result = ibc.tabComplete(user, "", new LinkedList<>()); - assertFalse(result.isPresent()); - - // Get the tab-complete list with one argument - LinkedList args = new LinkedList<>(); - args.add(""); - result = ibc.tabComplete(user, "", args); - assertTrue(result.isPresent()); - List r = result.get().stream().sorted().collect(Collectors.toList()); - // Compare the expected with the actual - String[] expectedNames = {"dave", "ed", "frank", "freddy", "george", "harry", "joe"}; - assertTrue(Arrays.equals(expectedNames, r.toArray())); - - // Get the tab-complete list with one letter argument - args = new LinkedList<>(); - args.add("d"); - result = ibc.tabComplete(user, "", args); - assertTrue(result.isPresent()); - r = result.get().stream().sorted().collect(Collectors.toList()); - // Compare the expected with the actual - String[] expectedName = {"dave"}; - assertTrue(Arrays.equals(expectedName, r.toArray())); - - // Get the tab-complete list with one letter argument - args = new LinkedList<>(); - args.add("fr"); - result = ibc.tabComplete(user, "", args); - assertTrue(result.isPresent()); - r = result.get().stream().sorted().collect(Collectors.toList()); - // Compare the expected with the actual - String[] expected = {"frank", "freddy"}; - assertTrue(Arrays.equals(expected, r.toArray())); - } -} diff --git a/src/test/java/world/bentobox/bentobox/commands/island/IslandBanlistCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/island/IslandBanlistCommandTest.java deleted file mode 100644 index cf30aa52a..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/island/IslandBanlistCommandTest.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.island; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class IslandBanlistCommandTest { - - private CompositeCommand ic; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private Island island; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - - // Parent command has no aliases - ic = mock(CompositeCommand.class); - when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); - when(ic.getTopLabel()).thenReturn("island"); - - // No island for player to begin with (set it later in the tests) - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Island Banned list initialization - island = mock(Island.class); - when(island.getBanned()).thenReturn(new HashSet<>()); - when(island.isBanned(Mockito.any())).thenReturn(false); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - - // IWM friendly name - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandBanlistCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testWithArgs() { - IslandBanlistCommand iubc = new IslandBanlistCommand(ic); - assertFalse(iubc.execute(user, iubc.getLabel(), Arrays.asList("bill"))); - // Verify show help - } - - @Test - public void testNoIsland() { - IslandBanlistCommand iubc = new IslandBanlistCommand(ic); - assertFalse(iubc.execute(user, iubc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("general.errors.no-island"); - } - - @Test - public void testBanlistNooneBanned() { - IslandBanlistCommand iubc = new IslandBanlistCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - assertTrue(iubc.execute(user, iubc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("commands.island.banlist.noone"); - } - - @Test - public void testBanlistBanned() { - IslandBanlistCommand iubc = new IslandBanlistCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Make a ban list - String[] names = {"adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry", "ian", "joe"}; - Set banned = new HashSet<>(); - Map uuidToName = new HashMap<>(); - for (int j = 0; j < names.length; j++) { - UUID uuid = UUID.randomUUID(); - banned.add(uuid); - uuidToName.put(uuid, names[j]); - } - when(island.getBanned()).thenReturn(banned); - // Respond to name queries - when(pm.getName(Mockito.any(UUID.class))).then(new Answer() { - - @Override - public String answer(InvocationOnMock invocation) throws Throwable { - return uuidToName.getOrDefault(invocation.getArgumentAt(0, UUID.class), "tastybento"); - } - - }); - assertTrue(iubc.execute(user, iubc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("commands.island.banlist.the-following"); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/island/IslandGoCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/island/IslandGoCommandTest.java deleted file mode 100644 index 0aa118572..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/island/IslandGoCommandTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.island; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.localization.TextVariables; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.PlayersManager; -import world.bentobox.bentobox.util.Util; - -/** - * Test for island go command - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, Util.class}) -public class IslandGoCommandTest { - private CompositeCommand ic; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private Island island; - private Player player; - - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - - when(plugin.getSettings()).thenReturn(s); - - // Player - player = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(player); - when(user.getName()).thenReturn("tastybento"); - - // Parent command has no aliases - ic = mock(CompositeCommand.class); - when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); - when(ic.getTopLabel()).thenReturn("island"); - - // No island for player to begin with (set it later in the tests) - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Island Banned list initialization - island = mock(Island.class); - when(island.getBanned()).thenReturn(new HashSet<>()); - when(island.isBanned(Mockito.any())).thenReturn(false); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - - // IWM friendly name - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - - // Number of homes - PowerMockito.mockStatic(Util.class); - // 1 home for now - when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(1); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandGoCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoArgsNoIsland() { - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(null); - IslandGoCommand igc = new IslandGoCommand(ic); - assertFalse(igc.execute(user, igc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("general.errors.no-island"); - - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandGoCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoArgs() { - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - IslandGoCommand igc = new IslandGoCommand(ic); - assertTrue(igc.execute(user, igc.getLabel(), new ArrayList<>())); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandGoCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoArgsMultipleHomes() { - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(3); - IslandGoCommand igc = new IslandGoCommand(ic); - assertTrue(igc.execute(user, igc.getLabel(), new ArrayList<>())); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandGoCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteArgs1MultipleHomes() { - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(3); - IslandGoCommand igc = new IslandGoCommand(ic); - List args = new ArrayList<>(); - args.add("1"); - assertTrue(igc.execute(user, igc.getLabel(), args)); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandGoCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteArgs2MultipleHomes() { - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(3); - IslandGoCommand igc = new IslandGoCommand(ic); - List args = new ArrayList<>(); - args.add("2"); - assertTrue(igc.execute(user, igc.getLabel(), args)); - Mockito.verify(user).sendMessage("commands.island.go.tip", TextVariables.LABEL, "island"); - } - - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandGoCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteArgsJunkMultipleHomes() { - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - when(Util.getPermValue(Mockito.any(Player.class), Mockito.anyString(), Mockito.anyInt())).thenReturn(3); - IslandGoCommand igc = new IslandGoCommand(ic); - List args = new ArrayList<>(); - args.add("sdfsdf"); - assertTrue(igc.execute(user, igc.getLabel(), args)); - } -} diff --git a/src/test/java/world/bentobox/bentobox/commands/island/IslandResetCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/island/IslandResetCommandTest.java deleted file mode 100644 index d56aacb85..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/island/IslandResetCommandTest.java +++ /dev/null @@ -1,322 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.island; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.scheduler.BukkitTask; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.PlayersManager; -import world.bentobox.bentobox.managers.island.NewIsland; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, NewIsland.class }) -public class IslandResetCommandTest { - - private CompositeCommand ic; - private UUID uuid; - private User user; - private Settings s; - private IslandsManager im; - private PlayersManager pm; - private World world; - private IslandWorldManager iwm; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // User, sometime use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - - // Parent command has no aliases - ic = mock(CompositeCommand.class); - when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); - when(ic.getTopLabel()).thenReturn("island"); - // World - world = mock(World.class); - when(ic.getWorld()).thenReturn(world); - - // No island for player to begin with (set it later in the tests) - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(plugin.getIslands()).thenReturn(im); - - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - BukkitTask task = mock(BukkitTask.class); - when(sch.runTaskLater(Mockito.any(), Mockito.any(Runnable.class), Mockito.any(Long.class))).thenReturn(task); - - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - - // IWM friendly name - iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - when(iwm.getResetLimit(Mockito.any())).thenReturn(3); - - - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandResetCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - * @throws IOException - */ - @Test - public void testNoIsland() throws IOException { - IslandResetCommand irc = new IslandResetCommand(ic); - // Test the reset command - // Does not have island - assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("general.errors.no-island"); - } - - @Test - public void testNotLeader() throws IOException { - IslandResetCommand irc = new IslandResetCommand(ic); - // Now has island, but is not the leader - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("general.errors.not-leader"); - } - - @Test - public void testHasTeam() throws IOException { - IslandResetCommand irc = new IslandResetCommand(ic); - // Now has island, but is not the leader - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now is owner, but still has team - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("commands.island.reset.must-remove-members"); - } - - @Test - public void testNoResetsLeft() throws IOException { - IslandResetCommand irc = new IslandResetCommand(ic); - // Now has island, but is not the leader - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now is owner, but still has team - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now has no team - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - - // Block based on no resets left - when(pm.getResets(Mockito.eq(world),Mockito.eq(uuid))).thenReturn(3); - - assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("commands.island.reset.none-left"); - } - - @Test - public void testNoConfirmationRequired() throws IOException { - IslandResetCommand irc = new IslandResetCommand(ic); - // Now has island, but is not the leader - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now is owner, but still has team - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now has no team - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - // Give the user some resets - when(pm.getResets(Mockito.eq(world), Mockito.eq(uuid))).thenReturn(1); - // Set so no confirmation required - when(s.isResetConfirmation()).thenReturn(false); - - // Old island mock - Island oldIsland = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland); - - // Mock up NewIsland builder - NewIsland.Builder builder = mock(NewIsland.Builder.class); - when(builder.player(Mockito.any())).thenReturn(builder); - when(builder.oldIsland(Mockito.any())).thenReturn(builder); - when(builder.reason(Mockito.any())).thenReturn(builder); - when(builder.build()).thenReturn(mock(Island.class)); - PowerMockito.mockStatic(NewIsland.class); - when(NewIsland.builder()).thenReturn(builder); - - // Reset command, no confirmation required - assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>())); - // Verify that build new island was called and the number of resets left shown - Mockito.verify(builder).build(); - Mockito.verify(user).sendMessage("commands.island.reset.resets-left", "[number]", "2"); - } - - @Test - public void testUnlimitedResets() throws IOException { - IslandResetCommand irc = new IslandResetCommand(ic); - // Now has island, but is not the leader - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now is owner, but still has team - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now has no team - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - // Give the user some resets - when(pm.getResets(Mockito.eq(world), Mockito.eq(uuid))).thenReturn(1); - // Set so no confirmation required - when(s.isResetConfirmation()).thenReturn(false); - - // Old island mock - Island oldIsland = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland); - - // Mock up NewIsland builder - NewIsland.Builder builder = mock(NewIsland.Builder.class); - when(builder.player(Mockito.any())).thenReturn(builder); - when(builder.oldIsland(Mockito.any())).thenReturn(builder); - when(builder.reason(Mockito.any())).thenReturn(builder); - when(builder.build()).thenReturn(mock(Island.class)); - PowerMockito.mockStatic(NewIsland.class); - when(NewIsland.builder()).thenReturn(builder); - // Test with unlimited resets - when(iwm.getResetLimit(Mockito.any())).thenReturn(-1); - - // Reset - assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>())); - // Verify that build new island was called and the number of resets left shown - Mockito.verify(builder).build(); - // This should not be shown - Mockito.verify(user, Mockito.never()).sendMessage("commands.island.reset.resets-left", "[number]", "1"); - } - - @Test - public void testConfirmationRequired() throws IOException { - IslandResetCommand irc = new IslandResetCommand(ic); - // Now has island, but is not the leader - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now is owner, but still has team - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now has no team - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - // Give the user some resets - when(pm.getResets(Mockito.eq(world), Mockito.eq(uuid))).thenReturn(1); - // Set so no confirmation required - when(s.isResetConfirmation()).thenReturn(false); - - // Old island mock - Island oldIsland = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland); - - // Mock up NewIsland builder - NewIsland.Builder builder = mock(NewIsland.Builder.class); - when(builder.player(Mockito.any())).thenReturn(builder); - when(builder.oldIsland(Mockito.any())).thenReturn(builder); - when(builder.reason(Mockito.any())).thenReturn(builder); - when(builder.build()).thenReturn(mock(Island.class)); - PowerMockito.mockStatic(NewIsland.class); - when(NewIsland.builder()).thenReturn(builder); - - // Require confirmation - when(s.isResetConfirmation()).thenReturn(true); - when(s.getConfirmationTime()).thenReturn(20); - - // Reset - assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>())); - // Check for message - Mockito.verify(user).sendMessage("general.confirm", "[seconds]", String.valueOf(s.getConfirmationTime())); - - // Send command again to confirm - assertTrue(irc.execute(user, irc.getLabel(), new ArrayList<>())); - - } - - @Test - public void testNewIslandError() throws IOException { - IslandResetCommand irc = new IslandResetCommand(ic); - // Now has island, but is not the leader - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now is owner, but still has team - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - // Now has no team - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - // Give the user some resets - when(pm.getResets(Mockito.eq(world), Mockito.eq(uuid))).thenReturn(1); - // Set so no confirmation required - when(s.isResetConfirmation()).thenReturn(false); - - // Old island mock - Island oldIsland = mock(Island.class); - when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(oldIsland); - - // Mock up NewIsland builder - NewIsland.Builder builder = mock(NewIsland.Builder.class); - when(builder.player(Mockito.any())).thenReturn(builder); - when(builder.oldIsland(Mockito.any())).thenReturn(builder); - when(builder.reason(Mockito.any())).thenReturn(builder); - when(builder.build()).thenThrow(new IOException()); - PowerMockito.mockStatic(NewIsland.class); - when(NewIsland.builder()).thenReturn(builder); - - // Require no confirmation - when(s.isResetConfirmation()).thenReturn(false); - - // Reset - assertFalse(irc.execute(user, irc.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage("commands.island.create.unable-create-island"); - - - } -} diff --git a/src/test/java/world/bentobox/bentobox/commands/island/IslandUnbanCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/island/IslandUnbanCommandTest.java deleted file mode 100644 index 4783ae583..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/island/IslandUnbanCommandTest.java +++ /dev/null @@ -1,253 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.island; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.localization.TextVariables; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.objects.Island; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class IslandUnbanCommandTest { - - private CompositeCommand ic; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private Island island; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - - // Parent command has no aliases - ic = mock(CompositeCommand.class); - when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // No island for player to begin with (set it later in the tests) - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Island Banned list initialization - island = mock(Island.class); - when(island.getBanned()).thenReturn(new HashSet<>()); - when(island.isBanned(Mockito.any())).thenReturn(false); - when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island); - - // IWM friendly name - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - } - - /** - * Test method for {@link world.bentobox.bentobox.commands.island.IslandUnbanCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - // Island ban command by itself - - // *** Error conditions *** - // Unban without an island - // Unban as not a team leader - // Unban unknown user - // Unban self - // Unban someone not banned - - // *** Working conditions *** - // Unban user - - @Test - public void testNoArgs() { - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - assertFalse(iubc.execute(user, iubc.getLabel(), new ArrayList<>())); - } - - @Test - public void testNoIsland() { - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - assertFalse(iubc.execute(user, iubc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.errors.no-island"); - } - - @Test - public void testNotOwner() { - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - assertFalse(iubc.execute(user, iubc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.errors.not-leader"); - } - - @Test - public void testUnknownUser() { - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(pm.getUUID(Mockito.anyString())).thenReturn(null); - assertFalse(iubc.execute(user, iubc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.errors.unknown-player"); - } - - @Test - public void testBanSelf() { - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(pm.getUUID(Mockito.anyString())).thenReturn(uuid); - assertFalse(iubc.execute(user, iubc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("commands.island.unban.cannot-unban-yourself"); - } - - @Test - public void testBanNotBanned() { - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID bannedUser = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(bannedUser); - when(island.isBanned(Mockito.eq(bannedUser))).thenReturn(false); - assertFalse(iubc.execute(user, iubc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("commands.island.unban.player-not-banned"); - } - - @Test - public void testUnbanUser() { - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID targetUUID = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(targetUUID); - PowerMockito.mockStatic(User.class); - User targetUser = mock(User.class); - when(targetUser.isOp()).thenReturn(false); - when(targetUser.isPlayer()).thenReturn(true); - when(targetUser.isOnline()).thenReturn(false); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser); - // Mark as banned - when(island.isBanned(Mockito.eq(targetUUID))).thenReturn(true); - - // Allow removing from ban list - when(island.removeFromBanList(Mockito.any())).thenReturn(true); - - assertTrue(iubc.execute(user, iubc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user).sendMessage("general.success"); - Mockito.verify(targetUser).sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName()); - } - - @Test - public void testCancelledUnban() { - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - UUID targetUUID = UUID.randomUUID(); - when(pm.getUUID(Mockito.anyString())).thenReturn(targetUUID); - PowerMockito.mockStatic(User.class); - User targetUser = mock(User.class); - when(targetUser.isOp()).thenReturn(false); - when(targetUser.isPlayer()).thenReturn(true); - when(targetUser.isOnline()).thenReturn(false); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser); - // Mark as banned - when(island.isBanned(Mockito.eq(targetUUID))).thenReturn(true); - - // Allow removing from ban list - when(island.removeFromBanList(Mockito.any())).thenReturn(false); - - assertFalse(iubc.execute(user, iubc.getLabel(), Arrays.asList("bill"))); - Mockito.verify(user, Mockito.never()).sendMessage("general.success"); - Mockito.verify(targetUser, Mockito.never()).sendMessage("commands.island.unban.you-are-unbanned", "[owner]", user.getName()); - } - - @Test - public void testTabComplete() { - Set banned = new HashSet<>(); - // Add ten people to the banned list - for (int i = 0; i < 10; i++) { - banned.add(UUID.randomUUID()); - } - when(island.getBanned()).thenReturn(banned); - when(pm.getName(Mockito.any())).thenReturn("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"); - IslandUnbanCommand iubc = new IslandUnbanCommand(ic); - User user = mock(User.class); - when(user.getUniqueId()).thenReturn(UUID.randomUUID()); - Optional> result = iubc.tabComplete(user, "", new LinkedList<>()); - assertTrue(result.isPresent()); - String[] names = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}; - assertTrue(Arrays.equals(names, result.get().toArray())); - } -} diff --git a/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamInviteCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamInviteCommandTest.java deleted file mode 100644 index cc503a650..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamInviteCommandTest.java +++ /dev/null @@ -1,213 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.island.team; - -import static org.junit.Assert.assertFalse; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class IslandTeamInviteCommandTest { - - private CompositeCommand ic; - private UUID uuid; - private User user; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - Settings s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - - when(plugin.getSettings()).thenReturn(s); - - // Player - Player p = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(p); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ic = mock(CompositeCommand.class); - when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - // Player Manager - pm = mock(PlayersManager.class); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - - // IWM friendly name - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - } - - /** - * Test method for {@link IslandTeamInviteCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoIsland() { - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false); - IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island")); - } - - /** - * Test method for {@link IslandTeamInviteCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNotTeamLeader() { - when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(notUUID); - IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-leader")); - } - - /** - * Test method for {@link IslandTeamInviteCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoTarget() { - IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Show help - } - - /** - * Test method for {@link IslandTeamInviteCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - - /** - * Test method for {@link IslandTeamInviteCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteOfflinePlayer() { - PowerMockito.mockStatic(User.class); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user); - when(user.isOnline()).thenReturn(false); - IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(uuid); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.offline-player")); - } - - /** - * Test method for {@link IslandTeamInviteCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteSamePlayer() { - PowerMockito.mockStatic(User.class); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user); - when(user.isOnline()).thenReturn(true); - IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(uuid); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.errors.cannot-invite-self")); - } - - - /** - * Test method for {@link IslandTeamInviteCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteDifferentPlayerInTeam() { - PowerMockito.mockStatic(User.class); - when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user); - when(user.isOnline()).thenReturn(true); - IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.errors.already-on-team")); - } - -} diff --git a/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamKickCommandTest.java deleted file mode 100644 index fdc4fba66..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamKickCommandTest.java +++ /dev/null @@ -1,268 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.island.team; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.LocalesManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class IslandTeamKickCommandTest { - - private CompositeCommand ic; - private UUID uuid; - private User user; - private Settings s; - private IslandsManager im; - private PlayersManager pm; - private UUID notUUID; - private IslandWorldManager iwm; - private Player player; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - - when(plugin.getSettings()).thenReturn(s); - - // Player - player = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - notUUID = UUID.randomUUID(); - while(notUUID.equals(uuid)) { - notUUID = UUID.randomUUID(); - } - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(player); - when(user.getName()).thenReturn("tastybento"); - User.setPlugin(plugin); - - // Parent command has no aliases - ic = mock(CompositeCommand.class); - when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true); - when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(uuid); - when(plugin.getIslands()).thenReturn(im); - - // Has team - pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Locales - LocalesManager lm = mock(LocalesManager.class); - when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation"); - when(plugin.getLocalesManager()).thenReturn(lm); - - // IWM friendly name - iwm = mock(IslandWorldManager.class); - when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock"); - when(plugin.getIWM()).thenReturn(iwm); - } - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoTeam() { - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team")); - } - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNotTeamLeader() { - when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(notUUID); - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-leader")); - } - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoTarget() { - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Show help - } - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteUnknownPlayer() { - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(null); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player")); - } - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteSamePlayer() { - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(uuid); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("commands.island.kick.cannot-kick")); - } - - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteDifferentPlayerNotInTeam() { - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(new HashSet<>()); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-in-team")); - } - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoConfirmation() { - when(s.isKickConfirmation()).thenReturn(false); - - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - Set members = new HashSet<>(); - members.add(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members); - - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID)); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteWithConfirmation() { - when(s.isKickConfirmation()).thenReturn(true); - - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - Set members = new HashSet<>(); - members.add(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members); - - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - // Confirmation required - Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.kick.type-again")); - } - - /** - * Test method for {@link IslandTeamKickCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteTestResets() { - when(s.isKickConfirmation()).thenReturn(false); - - String[] name = {"tastybento"}; - when(pm.getUUID(Mockito.any())).thenReturn(notUUID); - - Set members = new HashSet<>(); - members.add(notUUID); - when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members); - - // Require resets - when(iwm.isOnLeaveResetEnderChest(Mockito.any())).thenReturn(true); - Inventory enderChest = mock(Inventory.class); - when(player.getEnderChest()).thenReturn(enderChest); - when(iwm.isOnLeaveResetInventory(Mockito.any())).thenReturn(true); - PlayerInventory inv = mock(PlayerInventory.class); - when(player.getInventory()).thenReturn(inv); - when(iwm.isOnLeaveResetMoney(Mockito.any())).thenReturn(true); - - IslandTeamKickCommand itl = new IslandTeamKickCommand(ic); - assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name))); - Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID)); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - - Mockito.verify(enderChest).clear(); - Mockito.verify(inv).clear(); - } -} diff --git a/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamLeaveCommandTest.java b/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamLeaveCommandTest.java deleted file mode 100644 index dbfdc7baf..000000000 --- a/src/test/java/world/bentobox/bentobox/commands/island/team/IslandTeamLeaveCommandTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * - */ -package world.bentobox.bentobox.commands.island.team; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.scheduler.BukkitScheduler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.powermock.reflect.Whitebox; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.Settings; -import world.bentobox.bentobox.api.commands.CompositeCommand; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.CommandsManager; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.managers.IslandsManager; -import world.bentobox.bentobox.managers.PlayersManager; - -/** - * @author tastybento - * - */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class }) -public class IslandTeamLeaveCommandTest { - - private CompositeCommand ic; - private UUID uuid; - private User user; - private Settings s; - private IslandsManager im; - private IslandWorldManager iwm; - private Player player; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - // Set up plugin - BentoBox plugin = mock(BentoBox.class); - Whitebox.setInternalState(BentoBox.class, "instance", plugin); - - // Command manager - CommandsManager cm = mock(CommandsManager.class); - when(plugin.getCommandsManager()).thenReturn(cm); - - // Settings - s = mock(Settings.class); - when(s.getResetWait()).thenReturn(0L); - - when(plugin.getSettings()).thenReturn(s); - - // Player - player = mock(Player.class); - // Sometimes use Mockito.withSettings().verboseLogging() - user = mock(User.class); - when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); - when(user.getUniqueId()).thenReturn(uuid); - when(user.getPlayer()).thenReturn(player); - when(user.getName()).thenReturn("tastybento"); - - // Parent command has no aliases - ic = mock(CompositeCommand.class); - when(ic.getSubCommandAliases()).thenReturn(new HashMap<>()); - - // Player has island to begin with - im = mock(IslandsManager.class); - when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); - when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true); - when(plugin.getIslands()).thenReturn(im); - - // Has team - PlayersManager pm = mock(PlayersManager.class); - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true); - when(plugin.getPlayers()).thenReturn(pm); - - // Server & Scheduler - BukkitScheduler sch = mock(BukkitScheduler.class); - PowerMockito.mockStatic(Bukkit.class); - when(Bukkit.getScheduler()).thenReturn(sch); - - // Island World Manager - iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - } - - /** - * Test method for {@link IslandTeamLeaveCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoTeam() { - when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team")); - } - - /** - * Test method for {@link IslandTeamLeaveCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteInTeamLeader() { - IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.leave.cannot-leave")); - } - - /** - * Test method for {@link IslandTeamLeaveCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteNoConfirmation() { - when(s.isLeaveConfirmation()).thenReturn(false); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - // Add a team leader - null - when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(null); - - IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic); - assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid)); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - } - - /** - * Test method for {@link IslandTeamLeaveCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteWithConfirmation() { - when(s.isLeaveConfirmation()).thenReturn(true); - // 3 second timeout - when(s.getLeaveWait()).thenReturn(3L); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - // Add a team leader - null - when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(null); - - IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic); - assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>())); - // Confirmation required - Mockito.verify(user).sendMessage(Mockito.eq("general.confirm"), Mockito.eq("[seconds]"), Mockito.eq("0")); - } - - /** - * Test method for {@link IslandTeamLeaveCommand#execute(world.bentobox.bentobox.api.user.User, java.util.List)}. - */ - @Test - public void testExecuteTestResets() { - when(s.isLeaveConfirmation()).thenReturn(false); - when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false); - // Add a team leader - null - when(im.getTeamLeader(Mockito.any(), Mockito.any())).thenReturn(null); - - // Require resets - when(iwm.isOnLeaveResetEnderChest(Mockito.any())).thenReturn(true); - Inventory enderChest = mock(Inventory.class); - when(player.getEnderChest()).thenReturn(enderChest); - when(iwm.isOnLeaveResetInventory(Mockito.any())).thenReturn(true); - PlayerInventory inv = mock(PlayerInventory.class); - when(player.getInventory()).thenReturn(inv); - when(iwm.isOnLeaveResetMoney(Mockito.any())).thenReturn(true); - - IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic); - assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>())); - Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid)); - Mockito.verify(user).sendMessage(Mockito.eq("general.success")); - - Mockito.verify(enderChest).clear(); - Mockito.verify(inv).clear(); - } -}