mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Added test classes for coop, uncoop, trust and untrust commands.
This commit is contained in:
parent
c1a6a233a9
commit
6eeff3f383
@ -3,10 +3,6 @@ package world.bentobox.bentobox.api.commands.island.team;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
@ -94,13 +90,7 @@ public class IslandTeamCoopCommand extends CompositeCommand {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return Optional.empty();
|
||||
}
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
List<String> options = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> !p.getUniqueId().equals(user.getUniqueId()))
|
||||
.filter(p -> !island.getMemberSet().contains(p.getUniqueId()))
|
||||
.filter(p -> user.getPlayer().canSee(p))
|
||||
.map(Player::getName).collect(Collectors.toList());
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
return Optional.of(Util.tabLimit(Util.getOnlinePlayerList(user), lastArg));
|
||||
}
|
||||
}
|
||||
|
@ -65,11 +65,11 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
|
||||
private boolean unCoopCmd(User user, UUID targetUUID) {
|
||||
// Player cannot uncoop themselves
|
||||
if (user.getUniqueId().equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.coop.cannot-uncoop-yourself");
|
||||
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-yourself");
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.coop.cannot-uncoop-member");
|
||||
user.sendMessage("commands.island.team.uncoop.cannot-uncoop-member");
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
@ -82,7 +82,7 @@ public class IslandTeamUncoopCommand extends CompositeCommand {
|
||||
if (island != null) {
|
||||
island.removeMember(targetUUID);
|
||||
user.sendMessage("general.success");
|
||||
target.sendMessage("commands.island.team.coop.you-are-no-longer-a-coop-member", TextVariables.NAME, user.getName());
|
||||
target.sendMessage("commands.island.team.uncoop.you-are-no-longer-a-coop-member", TextVariables.NAME, user.getName());
|
||||
// Set cooldown
|
||||
if (getSettings().getInviteWait() > 0 && getParent() != null) {
|
||||
getParent().getSubCommand("coop").ifPresent(subCommand ->
|
||||
|
@ -0,0 +1,220 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.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.Collections;
|
||||
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.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;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamCoopCommandTest {
|
||||
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
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
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
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.inTeam(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);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
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 world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoisland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, 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);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.coop.cannot-coop-yourself"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasRank() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(notUUID));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.coop.already-has-rank"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteCoolDownActive() {
|
||||
// 10 minutes = 600 seconds
|
||||
when(s.getInviteWait()).thenReturn(10);
|
||||
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.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.Collections;
|
||||
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.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;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamTrustCommandTest {
|
||||
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
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
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
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.inTeam(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);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
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 world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoisland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, 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);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.trust.trust-in-yourself"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasRank() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(notUUID));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.trust.members-trusted"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamTrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteCoolDownActive() {
|
||||
// 10 minutes = 600 seconds
|
||||
when(s.getInviteWait()).thenReturn(10);
|
||||
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.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.Collections;
|
||||
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.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;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamUncoopCommandTest {
|
||||
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
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
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
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.inTeam(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);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
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 world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoisland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, 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);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.uncoop.cannot-uncoop-yourself"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasRank() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(notUUID));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.uncoop.cannot-uncoop-member"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUncoopCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteCoolDownActive() {
|
||||
// 10 minutes = 600 seconds
|
||||
when(s.getInviteWait()).thenReturn(10);
|
||||
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,220 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bentobox.api.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.Collections;
|
||||
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.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;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamUntrustCommandTest {
|
||||
|
||||
private CompositeCommand ic;
|
||||
private UUID uuid;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
private Settings s;
|
||||
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
|
||||
s = mock(Settings.class);
|
||||
when(s.getResetWait()).thenReturn(0L);
|
||||
when(s.getRankCommand(Mockito.anyString())).thenReturn(RanksManager.OWNER_RANK);
|
||||
|
||||
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.inTeam(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);
|
||||
island = mock(Island.class);
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.OWNER_RANK);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(island);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
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 world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoisland() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteLowRank() {
|
||||
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteNoTarget() {
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
|
||||
// Show help
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.unknown-player"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, 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);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.untrust.cannot-untrust-yourself"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecutePlayerHasRank() {
|
||||
PowerMockito.mockStatic(User.class);
|
||||
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(Collections.singleton(notUUID));
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bento")));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.untrust.cannot-untrust-member"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamUntrustCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteCoolDownActive() {
|
||||
// 10 minutes = 600 seconds
|
||||
when(s.getInviteWait()).thenReturn(10);
|
||||
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
|
||||
String[] name = {"tastybento"};
|
||||
itl.execute(user, itl.getLabel(), Arrays.asList(name));
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user