mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-02 06:28:13 +01:00
Moved hasTeam and hasIsland from PlayersManager to IslandsManager
Added IslandTeamInviteCommandTest.
This commit is contained in:
parent
030e7e44ca
commit
ea089b5b7d
@ -329,7 +329,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
* @return true if player is in a team
|
||||
*/
|
||||
protected boolean inTeam(User user) {
|
||||
return plugin.getPlayers().inTeam(user.getUniqueId());
|
||||
return plugin.getIslands().inTeam(user.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ public class AdminTeleportCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
} else {
|
||||
if (getPlayers().hasIsland(targetUUID) || getPlayers().inTeam(targetUUID)) {
|
||||
if (getIslands().hasIsland(targetUUID) || getIslands().inTeam(targetUUID)) {
|
||||
Location warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getIslandWorld());
|
||||
if (getLabel().equals("tpnether")) {
|
||||
warpSpot = getIslands().getIslandLocation(targetUUID).toVector().toLocation(getPlugin().getIslandWorldManager().getNetherWorld());
|
||||
|
@ -82,7 +82,7 @@ public class IslandBanCommand extends CompositeCommand {
|
||||
user.sendMessage("general.success");
|
||||
targetUser.sendMessage("commands.island.ban.owner-banned-you", "[owner]", user.getName());
|
||||
// If the player is online, has an island and on the banned island, move them home immediately
|
||||
if (targetUser.isOnline() && getPlayers().hasIsland(targetUser.getUniqueId()) && island.onIsland(targetUser.getLocation())) {
|
||||
if (targetUser.isOnline() && getIslands().hasIsland(targetUser.getUniqueId()) && island.onIsland(targetUser.getLocation())) {
|
||||
getIslands().homeTeleport(targetUser.getPlayer());
|
||||
island.getWorld().playSound(targetUser.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class IslandCreateCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.already-have-island");
|
||||
return false;
|
||||
}
|
||||
if (getPlayers().inTeam(user.getUniqueId())) {
|
||||
if (getIslands().inTeam(user.getUniqueId())) {
|
||||
return false;
|
||||
}
|
||||
user.sendMessage("commands.island.create.creating-island");
|
||||
|
@ -51,7 +51,7 @@ public class IslandResetCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
}
|
||||
if (getPlayers().inTeam(user.getUniqueId())) {
|
||||
if (getIslands().inTeam(user.getUniqueId())) {
|
||||
user.sendMessage("commands.island.reset.must-remove-members");
|
||||
return false;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
|
||||
return false;
|
||||
}
|
||||
// Check if player is already in a team
|
||||
if (getPlayers().inTeam(playerUUID)) {
|
||||
if (getIslands().inTeam(playerUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
|
||||
return false;
|
||||
}
|
||||
|
@ -35,11 +35,11 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
||||
public boolean execute(User user, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Player issuing the command must have an island
|
||||
UUID teamLeaderUUID = getTeamLeader(user);
|
||||
if (teamLeaderUUID == null) {
|
||||
if (!getIslands().hasIsland(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
UUID teamLeaderUUID = getTeamLeader(user);
|
||||
if (!(teamLeaderUUID.equals(playerUUID))) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
return false;
|
||||
@ -79,7 +79,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
||||
return false;
|
||||
}
|
||||
// Player cannot invite someone already on a team
|
||||
if (getPlayers().inTeam(invitedPlayerUUID)) {
|
||||
if (getIslands().inTeam(invitedPlayerUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.already-on-team");
|
||||
return false;
|
||||
}
|
||||
@ -115,7 +115,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommand {
|
||||
// Send message to online player
|
||||
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", NAME_PLACEHOLDER, user.getName());
|
||||
invitedPlayer.sendMessage("commands.island.team.invite.to-accept-or-reject", "[label]", getLabel());
|
||||
if (getPlayers().hasIsland(invitedPlayer.getUniqueId())) {
|
||||
if (getIslands().hasIsland(invitedPlayer.getUniqueId())) {
|
||||
invitedPlayer.sendMessage("commands.island.team.invite.you-will-lose-your-island");
|
||||
}
|
||||
return true;
|
||||
|
@ -30,7 +30,7 @@ public class IslandTeamKickCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
if (!getPlayers().inTeam(user.getUniqueId())) {
|
||||
if (!getIslands().inTeam(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return false;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class IslandTeamLeaveCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
if (!getPlayers().inTeam(user.getUniqueId())) {
|
||||
if (!getIslands().inTeam(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return false;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
if (!getPlayers().inTeam(user.getUniqueId())) {
|
||||
if (!getIslands().inTeam(user.getUniqueId())) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return true;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
|
||||
public boolean execute(User user, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Can use if in a team
|
||||
boolean inTeam = getPlugin().getPlayers().inTeam(playerUUID);
|
||||
boolean inTeam = getPlugin().getIslands().inTeam(playerUUID);
|
||||
UUID teamLeaderUUID = getTeamLeader(user);
|
||||
if (!(inTeam && teamLeaderUUID.equals(playerUUID))) {
|
||||
user.sendMessage("general.errors.not-leader");
|
||||
@ -48,7 +48,7 @@ public class IslandTeamSetownerCommand extends AbstractIslandTeamCommand {
|
||||
user.sendMessage("general.errors.unknown-player");
|
||||
return false;
|
||||
}
|
||||
if (!getPlayers().inTeam(playerUUID)) {
|
||||
if (!getIslands().inTeam(playerUUID)) {
|
||||
user.sendMessage("general.errors.no-team");
|
||||
return false;
|
||||
}
|
||||
|
@ -691,7 +691,7 @@ public class Island implements DataObject {
|
||||
* @param user - user who is requesting
|
||||
*/
|
||||
public void showMembers(BSkyBlock plugin, User user) {
|
||||
if (plugin.getPlayers().inTeam(user.getUniqueId())) {
|
||||
if (plugin.getIslands().inTeam(user.getUniqueId())) {
|
||||
user.sendMessage("commands.admin.info.team-members-title");
|
||||
members.forEach((u, i) -> {
|
||||
if (owner.equals(u)) {
|
||||
|
@ -427,7 +427,7 @@ public class IslandsManager {
|
||||
}
|
||||
// Home location either isn't safe, or does not exist so try the island
|
||||
// location
|
||||
if (plugin.getPlayers().inTeam(playerUUID)) {
|
||||
if (plugin.getIslands().inTeam(playerUUID)) {
|
||||
l = plugin.getIslands().getIslandLocation(playerUUID);
|
||||
if (isSafeLocation(l)) {
|
||||
plugin.getPlayers().setHomeLocation(playerUUID, l, number);
|
||||
@ -721,7 +721,7 @@ public class IslandsManager {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (island.inIslandSpace(player.getLocation().getBlockX(), player.getLocation().getBlockZ())) {
|
||||
// Teleport island players to their island home
|
||||
if (plugin.getPlayers().hasIsland(player.getUniqueId()) || plugin.getPlayers().inTeam(player.getUniqueId())) {
|
||||
if (hasIsland(player.getUniqueId()) || plugin.getIslands().inTeam(player.getUniqueId())) {
|
||||
homeTeleport(player);
|
||||
} else {
|
||||
// Move player to spawn
|
||||
@ -808,4 +808,13 @@ public class IslandsManager {
|
||||
islandCache.clear();
|
||||
handler.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a player is in a team
|
||||
* @param playerUUID - player's UUID
|
||||
* @return true if in team, false if not
|
||||
*/
|
||||
public boolean inTeam(UUID playerUUID) {
|
||||
return getMembers(playerUUID).size() > 1;
|
||||
}
|
||||
}
|
||||
|
@ -159,29 +159,6 @@ public class PlayersManager{
|
||||
return playerCache.get(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has an island.
|
||||
*
|
||||
* @param playerUUID - the player's UUID
|
||||
* - string name of player
|
||||
* @return true if player has island
|
||||
*/
|
||||
public boolean hasIsland(final UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return plugin.getIslands().hasIsland(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player is in a Team from cache if available
|
||||
*
|
||||
* @param playerUUID - the player's UUID
|
||||
* @return true if player in a team
|
||||
*/
|
||||
public boolean inTeam(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return plugin.getIslands().getMembers(playerUUID).size() > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the home location for the player
|
||||
* @param playerUUID - the player's UUID
|
||||
|
@ -82,11 +82,12 @@ public class DefaultHelpCommandTest {
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(false);
|
||||
// Has team
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
pm = mock(PlayersManager.class);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
|
@ -101,7 +101,7 @@ public class IslandBanCommandTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
|
@ -97,7 +97,7 @@ public class IslandBanlistCommandTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
|
@ -92,7 +92,7 @@ public class IslandResetCommandTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
@ -143,7 +143,7 @@ public class IslandResetCommandTest {
|
||||
// Now is owner, but still has team
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(true);
|
||||
// Now has no team
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
|
||||
// Block based on no resets left
|
||||
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(0);
|
||||
@ -160,7 +160,7 @@ public class IslandResetCommandTest {
|
||||
// Now is owner, but still has team
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(true);
|
||||
// Now has no team
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
// Give the user some resets
|
||||
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
|
||||
|
||||
@ -176,7 +176,7 @@ public class IslandResetCommandTest {
|
||||
// Now is owner, but still has team
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(true);
|
||||
// Now has no team
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
// Give the user some resets
|
||||
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
|
||||
// Set so no confirmation required
|
||||
@ -210,7 +210,7 @@ public class IslandResetCommandTest {
|
||||
// Now is owner, but still has team
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(true);
|
||||
// Now has no team
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
// Give the user some resets
|
||||
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
|
||||
// Set so no confirmation required
|
||||
@ -247,7 +247,7 @@ public class IslandResetCommandTest {
|
||||
// Now is owner, but still has team
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(true);
|
||||
// Now has no team
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
// Give the user some resets
|
||||
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
|
||||
// Set so no confirmation required
|
||||
@ -288,7 +288,7 @@ public class IslandResetCommandTest {
|
||||
// Now is owner, but still has team
|
||||
when(im.isOwner(Mockito.eq(uuid))).thenReturn(true);
|
||||
// Now has no team
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
// Give the user some resets
|
||||
when(pm.getResetsLeft(Mockito.eq(uuid))).thenReturn(1);
|
||||
// Set so no confirmation required
|
||||
|
@ -97,7 +97,7 @@ public class IslandUnbanCommandTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
|
@ -0,0 +1,209 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package us.tastybento.bskyblock.commands.island.teams;
|
||||
|
||||
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 us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.Settings;
|
||||
import us.tastybento.bskyblock.api.user.User;
|
||||
import us.tastybento.bskyblock.commands.IslandCommand;
|
||||
import us.tastybento.bskyblock.managers.CommandsManager;
|
||||
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||
public class IslandTeamInviteCommandTest {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private IslandCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private Settings s;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
plugin = mock(BSkyBlock.class);
|
||||
Whitebox.setInternalState(BSkyBlock.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(s.getResetLimit()).thenReturn(3);
|
||||
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(IslandCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any())).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any())).thenReturn(true);
|
||||
when(im.getTeamLeader(Mockito.any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
when(im.inTeam(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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoIsland() {
|
||||
when(im.hasIsland(Mockito.eq(uuid))).thenReturn(false);
|
||||
IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNotTeamLeader() {
|
||||
when(im.getTeamLeader(Mockito.any())).thenReturn(notUUID);
|
||||
IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-leader"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand#execute(us.tastybento.bskyblock.api.user.User, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamInviteCommand itl = new IslandTeamInviteCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand#execute(us.tastybento.bskyblock.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, Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand#execute(us.tastybento.bskyblock.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, Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.offline-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand#execute(us.tastybento.bskyblock.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, Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.cannot-invite-self"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand#execute(us.tastybento.bskyblock.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())).thenReturn(true);
|
||||
assertFalse(itl.execute(user, Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.invite.already-on-team"));
|
||||
}
|
||||
|
||||
}
|
@ -100,7 +100,7 @@ public class IslandTeamKickCommandTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
@ -120,7 +120,7 @@ public class IslandTeamKickCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTeam() {
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team"));
|
||||
|
@ -89,7 +89,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
@ -104,7 +104,7 @@ public class IslandTeamLeaveCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTeam() {
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(false);
|
||||
IslandTeamLeaveCommand itl = new IslandTeamLeaveCommand(ic);
|
||||
assertFalse(itl.execute(user, new ArrayList<>()));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team"));
|
||||
|
@ -106,7 +106,7 @@ public class LockAndBanListenerTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
|
@ -107,7 +107,7 @@ public class UpDownClickTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
|
@ -109,7 +109,6 @@ public class IslandsManagerTest {
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(pm.inTeam(Mockito.eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Server & Scheduler
|
||||
|
Loading…
Reference in New Issue
Block a user