Fix tests
This commit is contained in:
parent
37de29b5f6
commit
3702870095
|
@ -116,7 +116,7 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
public boolean canExecute(User user, String label, List<String> args) {
|
||||
this.user = user;
|
||||
// Player issuing the command must have an island
|
||||
island = getIslands().getPrimaryIsland(getWorld(), user.getUniqueId());
|
||||
|
@ -146,8 +146,14 @@ public class IslandTeamCommand extends CompositeCommand {
|
|||
user.sendMessage("commands.island.team.invite.errors.island-is-full");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Show members of island
|
||||
showMembers().forEach(user::sendRawMessage);
|
||||
// Show the panel
|
||||
build();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
|
@ -149,33 +148,23 @@ public class IslandTeamCommandTest extends RanksManagerBeforeClassTest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoIsland() {
|
||||
public void testCanExecuteUserStringListOfStringNoIsland() {
|
||||
when(im.getPrimaryIsland(world, uuid)).thenReturn(null);
|
||||
assertFalse(tc.execute(user, "team", Collections.emptyList()));
|
||||
assertFalse(tc.canExecute(user, "team", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringIslandIsNotFull() {
|
||||
assertTrue(tc.execute(user, "team", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.you-can-invite"), eq(TextVariables.NUMBER), eq("3"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringIslandIsFull() {
|
||||
public void testCanExecuteUserStringListOfStringIslandIsFull() {
|
||||
// Max members
|
||||
when(im.getMaxMembers(eq(island), eq(RanksManager.MEMBER_RANK))).thenReturn(0);
|
||||
assertTrue(tc.execute(user, "team", Collections.emptyList()));
|
||||
assertTrue(tc.canExecute(user, "team", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.errors.island-is-full"));
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import static org.mockito.Mockito.never;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -19,6 +20,10 @@ import java.util.UUID;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFactory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
@ -92,6 +97,10 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
|
|||
// Settings
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
// Data folder for panels
|
||||
when(plugin.getDataFolder())
|
||||
.thenReturn(new File("src" + File.separator + "main" + File.separator + "resources"));
|
||||
|
||||
// Player & users
|
||||
PowerMockito.mockStatic(User.class);
|
||||
|
||||
|
@ -165,6 +174,15 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
|
|||
// Parent command
|
||||
when(ic.getTopLabel()).thenReturn("island");
|
||||
|
||||
// Mock item factory (for itemstacks)
|
||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||
ItemMeta bannerMeta = mock(ItemMeta.class);
|
||||
when(itemFactory.getItemMeta(any())).thenReturn(bannerMeta);
|
||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||
Inventory inventory = mock(Inventory.class);
|
||||
when(Bukkit.createInventory(eq(null), anyInt(), any())).thenReturn(inventory);
|
||||
when(Bukkit.createInventory(eq(null), any(InventoryType.class), any())).thenReturn(inventory);
|
||||
|
||||
// Command under test
|
||||
itl = new IslandTeamInviteCommand(ic);
|
||||
|
||||
|
|
Loading…
Reference in New Issue