Fixes rank checking for team invites

Only owners could invite players successfully. This now checks based on
rank.
Added a method to allow rank checking on UUID. Had to make tests be
specific to the User.class.

https://github.com/BentoBoxWorld/BentoBox/issues/1377
This commit is contained in:
tastybento 2020-05-30 11:22:05 -07:00
parent 0e10563ae6
commit d6b2a88b32
15 changed files with 125 additions and 88 deletions

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.api.commands.island.team;
import java.util.List;
import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
import world.bentobox.bentobox.api.events.island.IslandEvent;
@ -43,7 +44,14 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
}
// Get the island owner
prospectiveOwnerUUID = itc.getInviter(playerUUID);
if (prospectiveOwnerUUID == null || !getIslands().hasIsland(getWorld(), prospectiveOwnerUUID)) {
if (prospectiveOwnerUUID == null) {
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
return false;
}
// Check rank to of inviter
Island island = getIslands().getIsland(getWorld(), prospectiveOwnerUUID);
String inviteUsage = getParent().getSubCommand("invite").map(CompositeCommand::getUsage).orElse("");
if (island == null || island.getRank(prospectiveOwnerUUID) < island.getRankCommand(inviteUsage)) {
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
itc.removeInvite(playerUUID);
return false;
@ -92,12 +100,12 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
if (island != null) {
island.setRank(user, RanksManager.TRUSTED_RANK);
IslandEvent.builder()
.island(island)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(user), RanksManager.TRUSTED_RANK)
.build();
.island(island)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(user), RanksManager.TRUSTED_RANK)
.build();
inviter.sendMessage("commands.island.team.trust.success", TextVariables.NAME, user.getName());
user.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, inviter.getName());
}
@ -113,12 +121,12 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
if (island != null) {
island.setRank(user, RanksManager.COOP_RANK);
IslandEvent.builder()
.island(island)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(user), RanksManager.COOP_RANK)
.build();
.island(island)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(island.getRank(user), RanksManager.COOP_RANK)
.build();
inviter.sendMessage("commands.island.team.coop.success", TextVariables.NAME, user.getName());
user.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, inviter.getName());
}
@ -165,12 +173,12 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
.involvedPlayer(playerUUID)
.build();
IslandEvent.builder()
.island(teamIsland)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(teamIsland.getRank(user), RanksManager.MEMBER_RANK)
.build();
.island(teamIsland)
.involvedPlayer(user.getUniqueId())
.admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE)
.rankChange(teamIsland.getRank(user), RanksManager.MEMBER_RANK)
.build();
}
private void cleanPlayer(User user) {

View File

@ -525,6 +525,16 @@ public class Island implements DataObject {
return members.getOrDefault(user.getUniqueId(), RanksManager.VISITOR_RANK);
}
/**
* Get the rank of user for this island
* @param userUUID - the User's UUID
* @return rank integer
* @since 1.14.0
*/
public int getRank(UUID userUUID) {
return members.getOrDefault(userUUID, RanksManager.VISITOR_RANK);
}
@Override
public String getUniqueId() {
return uniqueId;

View File

@ -193,7 +193,7 @@ public class AdminGetrankCommandTest {
public void testExecuteUserStringListOfString() {
// Set the target
testCanExecuteKnownPlayerHasIslandSuccess();
when(island.getRank(any())).thenReturn(RanksManager.SUB_OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.SUB_OWNER_RANK);
when(user.getTranslation(any())).thenReturn("sub-owner", "sub-owner");
when(island.getOwner()).thenReturn(targetUUID);
when(pm.getName(targetUUID)).thenReturn("tastybento");

View File

@ -214,7 +214,7 @@ public class AdminSetrankCommandTest {
// Set the target
testCanExecuteKnownPlayerHasIslandSuccess();
Island island = mock(Island.class);
when(island.getRank(any())).thenReturn(RanksManager.SUB_OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.SUB_OWNER_RANK);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
assertTrue(c.execute(user, "", Arrays.asList("tastybento", "member")));
verify(user).sendMessage(eq("commands.admin.setrank.rank-set"),

View File

@ -124,7 +124,7 @@ public class IslandBanCommandTest {
// Island Banned list initialization
when(island.getBanned()).thenReturn(new HashSet<>());
when(island.isBanned(any())).thenReturn(false);
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
@ -205,7 +205,7 @@ public class IslandBanCommandTest {
@Test
public void testTooLowRank() {
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(ibc.canExecute(user, ibc.getLabel(), Collections.singletonList("bill")));
verify(user).sendMessage("general.errors.no-permission");

View File

@ -155,7 +155,7 @@ public class IslandBanlistCommandTest {
*/
@Test
public void testTooLowRank() {
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
IslandBanlistCommand iubc = new IslandBanlistCommand(ic);
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.emptyList()));

View File

@ -129,7 +129,7 @@ public class IslandExpelCommandTest {
when(Bukkit.getScheduler()).thenReturn(sch);
// Island Banned list initialization
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
@ -240,7 +240,7 @@ public class IslandExpelCommandTest {
@Test
public void testCanExecuteLowRank() {
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
when(island.getRank(any())).thenReturn(RanksManager.VISITOR_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(iec.canExecute(user, "", Collections.singletonList("tasty")));
verify(user).sendMessage("general.errors.no-permission");

View File

@ -115,7 +115,7 @@ public class IslandUnbanCommandTest {
// Island Banned list initialization
when(island.getBanned()).thenReturn(new HashSet<>());
when(island.isBanned(any())).thenReturn(false);
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
@ -174,7 +174,7 @@ public class IslandUnbanCommandTest {
public void testTooLowRank() {
IslandUnbanCommand iubc = new IslandUnbanCommand(ic);
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(iubc.canExecute(user, iubc.getLabel(), Collections.singletonList("bill")));
verify(user).sendMessage("general.errors.no-permission");

View File

@ -107,7 +107,7 @@ public class IslandTeamCoopCommandTest {
when(im.isOwner(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
// Island
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(island.getMemberSet(anyInt(), any(Boolean.class))).thenReturn(ImmutableSet.of(uuid));
when(im.getIsland(any(), Mockito.any(User.class))).thenReturn(island);
when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island);
@ -163,7 +163,7 @@ public class IslandTeamCoopCommandTest {
*/
@Test
public void testCanExecuteLowRank() {
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
IslandTeamCoopCommand itl = new IslandTeamCoopCommand(ic);
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill")));

View File

@ -114,8 +114,11 @@ public class IslandTeamInviteAcceptCommandTest {
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
when(im.isOwner(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
// Island
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(UUID.class))).thenReturn(RanksManager.OWNER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
@ -201,11 +204,27 @@ public class IslandTeamInviteAcceptCommandTest {
public void testCanExecuteInvalidInvite() {
when(itc.isInvited(any())).thenReturn(true);
when(im.inTeam(any(), any())).thenReturn(false);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
when(island.getRank(any(UUID.class))).thenReturn(RanksManager.VISITOR_RANK);
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
verify(user).sendMessage("commands.island.team.invite.errors.invalid-invite");
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteAcceptCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteSubOwnerRankInvite() {
when(itc.isInvited(any())).thenReturn(true);
when(im.inTeam(any(), any())).thenReturn(false);
when(island.getRank(any(UUID.class))).thenReturn(RanksManager.SUB_OWNER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.SUB_OWNER_RANK);
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
verify(user, never()).sendMessage("commands.island.team.invite.errors.invalid-invite");
verify(pim).callEvent(any());
}
/**
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteAcceptCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@ -213,9 +232,8 @@ public class IslandTeamInviteAcceptCommandTest {
public void testCanExecuteInvalidInviteNull() {
when(itc.getInviter(any())).thenReturn(null);
when(itc.isInvited(any())).thenReturn(true);
when(im.inTeam(any(), any())).thenReturn(false);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
verify(user).sendMessage("commands.island.team.invite.errors.invalid-invite");
}
@ -228,8 +246,9 @@ public class IslandTeamInviteAcceptCommandTest {
when(itc.getInviter(any())).thenReturn(notUUID);
when(itc.getInvite(any())).thenReturn(invite);
when(im.inTeam(any(), any())).thenReturn(false);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
verify(user, never()).sendMessage("commands.island.team.invite.errors.invalid-invite");
verify(pim).callEvent(any());
}
@ -243,8 +262,9 @@ public class IslandTeamInviteAcceptCommandTest {
when(itc.getInvite(any())).thenReturn(invite);
when(invite.getType()).thenReturn(Type.TRUST);
when(im.inTeam(any(), any())).thenReturn(false);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
verify(user, never()).sendMessage("commands.island.team.invite.errors.invalid-invite");
// No event
verify(pim, never()).callEvent(any());
}
@ -259,8 +279,9 @@ public class IslandTeamInviteAcceptCommandTest {
when(itc.getInvite(any())).thenReturn(invite);
when(invite.getType()).thenReturn(Invite.Type.COOP);
when(im.inTeam(any(), any())).thenReturn(false);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
verify(user, never()).sendMessage("commands.island.team.invite.errors.invalid-invite");
// No event
verify(pim, never()).callEvent(any());
}
@ -286,6 +307,8 @@ public class IslandTeamInviteAcceptCommandTest {
when(teb.build()).thenReturn(ibe);
when(TeamEvent.builder()).thenReturn(teb);
assertFalse(c.canExecute(user, "accept", Collections.emptyList()));
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
verify(user, never()).sendMessage("commands.island.team.invite.errors.invalid-invite");
}
/**

View File

@ -125,7 +125,7 @@ public class IslandTeamInviteCommandTest {
when(im.hasIsland(any(), eq(uuid))).thenReturn(true);
when(im.isOwner(any(), eq(uuid))).thenReturn(true);
when(im.getOwner(any(), eq(uuid))).thenReturn(uuid);
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(im.getIsland(any(), eq(user))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
@ -188,7 +188,7 @@ public class IslandTeamInviteCommandTest {
*/
@Test
public void testCanExecuteLowRank() {
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("target")));
verify(user).sendMessage(eq("general.errors.no-permission"));

View File

@ -254,7 +254,7 @@ public class IslandTeamKickCommandTest {
IslandTeamKickCommand itl = new IslandTeamKickCommand(ic);
when(pm.getUUID(any())).thenReturn(notUUID);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any())).thenReturn(RanksManager.VISITOR_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("poslovitch")));
verify(user).sendMessage(eq("general.errors.no-permission"));
}

View File

@ -90,7 +90,7 @@ public class IslandTeamTrustCommandTest {
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
when(user.isOp()).thenReturn(false);
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(4);
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(4);
uuid = UUID.randomUUID();
notUUID = UUID.randomUUID();
@ -115,8 +115,8 @@ public class IslandTeamTrustCommandTest {
when(im.isOwner(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
// Island
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
when(island.getMemberSet(anyInt(), any(Boolean.class))).thenReturn(ImmutableSet.of(uuid));
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(island.getMemberSet(anyInt(), any(Boolean.class))).thenReturn(ImmutableSet.of(uuid));
when(im.getIsland(any(), Mockito.any(User.class))).thenReturn(island);
when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
@ -170,7 +170,7 @@ public class IslandTeamTrustCommandTest {
*/
@Test
public void testCanExecuteLowRank() {
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_RANK);
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.singletonList("bill")));
@ -261,7 +261,7 @@ public class IslandTeamTrustCommandTest {
// Can execute
when(pm.getUUID(any())).thenReturn(notUUID);
when(im.getMembers(any(), any())).thenReturn(Collections.emptySet());
when(island.getRank(any())).thenReturn(RanksManager.VISITOR_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList("tastybento")));
// Execute
@ -279,7 +279,7 @@ public class IslandTeamTrustCommandTest {
// Can execute
when(pm.getUUID(any())).thenReturn(notUUID);
when(im.getMembers(any(), any())).thenReturn(Collections.emptySet());
when(island.getRank(any())).thenReturn(RanksManager.VISITOR_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList("target")));
@ -290,7 +290,7 @@ public class IslandTeamTrustCommandTest {
verify(island).setRank(target, RanksManager.TRUSTED_RANK);
verify(targetPlayer).sendMessage("commands.island.team.trust.you-are-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)}.
*/
@ -301,7 +301,7 @@ public class IslandTeamTrustCommandTest {
// Can execute
when(pm.getUUID(any())).thenReturn(notUUID);
when(im.getMembers(any(), any())).thenReturn(Collections.emptySet());
when(island.getRank(any())).thenReturn(RanksManager.VISITOR_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.VISITOR_RANK);
IslandTeamTrustCommand itl = new IslandTeamTrustCommand(ic);
assertTrue(itl.canExecute(user, itl.getLabel(), Collections.singletonList("target")));
@ -314,5 +314,5 @@ public class IslandTeamTrustCommandTest {
verify(targetPlayer).sendMessage(eq("commands.island.team.invite.to-accept-or-reject"));
verify(island, never()).setRank(target, RanksManager.TRUSTED_RANK);
}
}

View File

@ -1,12 +1,12 @@
/**
*
*/
package world.bentobox.bentobox.api.commands.island.team;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
@ -27,7 +27,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@ -84,7 +83,7 @@ public class IslandTeamUncoopCommandTest {
// Player
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
// Sometimes use withSettings().verboseLogging()
user = mock(User.class);
when(user.isOp()).thenReturn(false);
uuid = UUID.randomUUID();
@ -103,18 +102,18 @@ public class IslandTeamUncoopCommandTest {
// 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.getOwner(Mockito.any(), Mockito.any())).thenReturn(uuid);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
when(im.inTeam(any(), any(UUID.class))).thenReturn(true);
when(im.isOwner(any(), any())).thenReturn(true);
when(im.getOwner(any(), 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(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
// Has team
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
// Player Manager
pm = mock(PlayersManager.class);
@ -128,12 +127,12 @@ public class IslandTeamUncoopCommandTest {
// Locales
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(lm.get(any(), 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(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
when(plugin.getIWM()).thenReturn(iwm);
}
@ -142,11 +141,11 @@ public class IslandTeamUncoopCommandTest {
*/
@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);
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
when(im.inTeam(any(), 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"));
verify(user).sendMessage(eq("general.errors.no-island"));
}
/**
@ -154,11 +153,11 @@ public class IslandTeamUncoopCommandTest {
*/
@Test
public void testExecuteLowRank() {
when(island.getRank(Mockito.any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(anyString())).thenReturn(RanksManager.OWNER_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"));
verify(user).sendMessage(eq("general.errors.no-permission"));
}
/**
@ -177,9 +176,9 @@ public class IslandTeamUncoopCommandTest {
@Test
public void testExecuteUnknownPlayer() {
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
when(pm.getUUID(Mockito.any())).thenReturn(null);
when(pm.getUUID(any())).thenReturn(null);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
}
/**
@ -188,12 +187,12 @@ public class IslandTeamUncoopCommandTest {
@Test
public void testExecuteSamePlayer() {
PowerMockito.mockStatic(User.class);
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
when(User.getInstance(any(UUID.class))).thenReturn(user);
when(user.isOnline()).thenReturn(true);
IslandTeamUncoopCommand itl = new IslandTeamUncoopCommand(ic);
when(pm.getUUID(Mockito.any())).thenReturn(uuid);
when(pm.getUUID(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"));
verify(user).sendMessage(eq("commands.island.team.uncoop.cannot-uncoop-yourself"));
}
@ -203,14 +202,14 @@ public class IslandTeamUncoopCommandTest {
@Test
public void testExecutePlayerHasRank() {
PowerMockito.mockStatic(User.class);
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(user);
when(User.getInstance(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));
when(pm.getUUID(any())).thenReturn(notUUID);
when(im.inTeam(any(), any())).thenReturn(true);
when(im.getMembers(any(), 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"));
verify(user).sendMessage(eq("commands.island.team.uncoop.cannot-uncoop-member"));
}
/**
@ -228,7 +227,7 @@ public class IslandTeamUncoopCommandTest {
@Test
public void testTabCompleteNoIsland() {
// No island
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(null);
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
IslandTeamUncoopCommand ibc = new IslandTeamUncoopCommand(ic);
// Set up the user
User user = mock(User.class);
@ -264,9 +263,9 @@ public class IslandTeamUncoopCommandTest {
// Return a set of players
PowerMockito.mockStatic(Bukkit.class);
OfflinePlayer offlinePlayer = mock(OfflinePlayer.class);
when(Bukkit.getOfflinePlayer(Mockito.any(UUID.class))).thenReturn(offlinePlayer);
when(Bukkit.getOfflinePlayer(any(UUID.class))).thenReturn(offlinePlayer);
when(offlinePlayer.getName()).thenReturn("adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry", "ian", "joe");
when(island.getRank(Mockito.any())).thenReturn(
when(island.getRank(any(User.class))).thenReturn(
RanksManager.COOP_RANK,
RanksManager.COOP_RANK,
RanksManager.COOP_RANK,

View File

@ -1,6 +1,3 @@
/**
*
*/
package world.bentobox.bentobox.api.commands.island.team;
import static org.junit.Assert.assertFalse;
@ -108,7 +105,7 @@ public class IslandTeamUntrustCommandTest {
when(im.isOwner(any(), any())).thenReturn(true);
when(im.getOwner(any(), any())).thenReturn(uuid);
island = mock(Island.class);
when(island.getRank(any())).thenReturn(RanksManager.OWNER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.OWNER_RANK);
when(im.getIsland(any(), any(User.class))).thenReturn(island);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
@ -154,7 +151,7 @@ public class IslandTeamUntrustCommandTest {
*/
@Test
public void testExecuteLowRank() {
when(island.getRank(any())).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRank(any(User.class))).thenReturn(RanksManager.MEMBER_RANK);
when(island.getRankCommand(any())).thenReturn(RanksManager.OWNER_RANK);
IslandTeamUntrustCommand itl = new IslandTeamUntrustCommand(ic);
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("bill")));
@ -266,7 +263,7 @@ public class IslandTeamUntrustCommandTest {
OfflinePlayer offlinePlayer = mock(OfflinePlayer.class);
when(Bukkit.getOfflinePlayer(any(UUID.class))).thenReturn(offlinePlayer);
when(offlinePlayer.getName()).thenReturn("adam", "ben", "cara", "dave", "ed", "frank", "freddy", "george", "harry", "ian", "joe");
when(island.getRank(any())).thenReturn(
when(island.getRank(any(User.class))).thenReturn(
RanksManager.TRUSTED_RANK,
RanksManager.TRUSTED_RANK,
RanksManager.TRUSTED_RANK,