Fixed tests and logic with coop/trust limits

This commit is contained in:
Florian CUNY 2020-04-05 15:15:26 +02:00
parent 0f2ba0e202
commit 5b01f39f9e
4 changed files with 14 additions and 5 deletions

View File

@ -93,7 +93,7 @@ public class IslandTeamCoopCommand extends CompositeCommand {
target.sendMessage("commands.island.team.coop.name-has-invited-you", TextVariables.NAME, user.getName());
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
} else {
if (getMaxCoopSize(user) <= island.getMemberSet(RanksManager.COOP_RANK, false).size()) {
if (island.getMemberSet(RanksManager.COOP_RANK, false).size() > getMaxCoopSize(user)) {
user.sendMessage("commands.island.team.coop.is-full");
return false;
}

View File

@ -95,7 +95,7 @@ public class IslandTeamTrustCommand extends CompositeCommand {
target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName());
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
} else {
if (getMaxTrustSize(user) <= island.getMemberSet(RanksManager.TRUSTED_RANK, false).size()) {
if (island.getMemberSet(RanksManager.TRUSTED_RANK, false).size() > getMaxTrustSize(user)) {
user.sendMessage("commands.island.team.trust.is-full");
return false;
}

View File

@ -1,11 +1,9 @@
/**
*
*/
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.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@ -17,6 +15,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.UUID;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
@ -86,6 +86,8 @@ public class IslandTeamCoopCommandTest {
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
when(user.isOp()).thenReturn(false);
when(user.getPermissionValue(anyString(), anyInt())).thenReturn(4);
uuid = UUID.randomUUID();
notUUID = UUID.randomUUID();
while(notUUID.equals(uuid)) {
@ -106,6 +108,7 @@ public class IslandTeamCoopCommandTest {
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(im.getIsland(any(), Mockito.any(User.class))).thenReturn(island);
when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
@ -129,6 +132,7 @@ public class IslandTeamCoopCommandTest {
// IWM friendly name
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
when(iwm.getMaxCoopSize(any())).thenReturn(4);
when(plugin.getIWM()).thenReturn(iwm);
PlaceholdersManager phm = mock(PlaceholdersManager.class);

View File

@ -3,6 +3,7 @@ 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.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@ -15,6 +16,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.UUID;
import com.google.common.collect.ImmutableSet;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
@ -88,6 +90,8 @@ 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);
uuid = UUID.randomUUID();
notUUID = UUID.randomUUID();
while(notUUID.equals(uuid)) {
@ -112,6 +116,7 @@ public class IslandTeamTrustCommandTest {
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(im.getIsland(any(), Mockito.any(User.class))).thenReturn(island);
when(im.getIsland(any(), Mockito.any(UUID.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);