mirror of
https://github.com/BentoBoxWorld/AcidIsland.git
synced 2024-12-23 01:27:36 +01:00
Adds island near command.
Fixes tests.
This commit is contained in:
parent
c1b6520fcf
commit
541ec30de8
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>world.bentobox</groupId>
|
||||
<artifactId>acidisland</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.1-SNAPSHOT</version>
|
||||
|
||||
<name>AcidIsland</name>
|
||||
<description>AcidIsland is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock or AcidIsland.</description>
|
||||
|
@ -12,6 +12,7 @@ import world.bentobox.bentobox.api.commands.island.IslandExpelCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandGoCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandInfoCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandLanguageCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandNearCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandResetCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandResetnameCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandSethomeCommand;
|
||||
@ -54,6 +55,7 @@ public class AiCommand extends CompositeCommand {
|
||||
new IslandUnbanCommand(this);
|
||||
new IslandBanlistCommand(this);
|
||||
new IslandExpelCommand(this);
|
||||
new IslandNearCommand(this);
|
||||
// Team commands
|
||||
new IslandTeamCommand(this);
|
||||
}
|
||||
|
@ -1,15 +1,17 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.acidisland.commands;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -19,15 +21,19 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
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.acidisland.AISettings;
|
||||
import world.bentobox.acidisland.AcidIsland;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.BlueprintsManager;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
@ -40,9 +46,11 @@ import world.bentobox.bentobox.managers.IslandsManager;
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class AiCommandTest {
|
||||
|
||||
private static final int NUMBER_OF_COMMANDS = 18;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private Island island;
|
||||
private AcidIsland addon;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -66,6 +74,7 @@ public class AiCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.isPlayer()).thenReturn(true);
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Island World Manager
|
||||
@ -83,6 +92,24 @@ public class AiCommandTest {
|
||||
// Return the reference (USE THIS IN THE FUTURE)
|
||||
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgumentAt(0, String.class));
|
||||
|
||||
addon = mock(AcidIsland.class);
|
||||
AISettings settings = mock(AISettings.class);
|
||||
when(settings.getIslandCommand()).thenReturn("ai");
|
||||
when(addon.getSettings()).thenReturn(settings);
|
||||
|
||||
// Blueprints
|
||||
BlueprintsManager bpm = mock(BlueprintsManager.class);
|
||||
Map<String, BlueprintBundle> map = new HashMap<>();
|
||||
BlueprintBundle bun = mock(BlueprintBundle.class);
|
||||
when(bun.getDisplayName()).thenReturn("aaa", "bbb");
|
||||
map.put("aaa", bun);
|
||||
map.put("bbb", bun);
|
||||
when(bun.getUniqueId()).thenReturn("unique1", "unique2");
|
||||
when(bun.isRequirePermission()).thenReturn(true);
|
||||
when(bpm.getBlueprintBundles(Mockito.any())).thenReturn(map);
|
||||
when(plugin.getBlueprintsManager()).thenReturn(bpm);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -91,7 +118,6 @@ public class AiCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testAiCommand() {
|
||||
Addon addon = mock(Addon.class);
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertEquals("ai", cmd.getLabel());
|
||||
}
|
||||
@ -101,15 +127,13 @@ public class AiCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testSetup() {
|
||||
Addon addon = mock(Addon.class);
|
||||
when(addon.getPermissionPrefix()).thenReturn("acidisland.");
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertEquals("acidisland.island", cmd.getPermission());
|
||||
assertTrue(cmd.isOnlyPlayer());
|
||||
assertEquals("commands.ai.parameters", cmd.getParameters());
|
||||
assertEquals("commands.island.help.description", cmd.getDescription());
|
||||
// Number of commands = sub commands + help
|
||||
assertEquals("Number of sub commands registered", 17, cmd.getSubCommands().values().size());
|
||||
assertEquals("Number of sub commands registered", NUMBER_OF_COMMANDS, cmd.getSubCommands().values().size());
|
||||
|
||||
}
|
||||
|
||||
@ -118,9 +142,8 @@ public class AiCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNullUsers() {
|
||||
Addon addon = mock(Addon.class);
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertFalse(cmd.execute(null, "ai", Collections.emptyList()));
|
||||
assertFalse(cmd.execute(null, "island", Collections.emptyList()));
|
||||
|
||||
}
|
||||
|
||||
@ -129,31 +152,75 @@ public class AiCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringUnknownCommand() {
|
||||
Addon addon = mock(Addon.class);
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertFalse(cmd.execute(user, "ai", Collections.singletonList("unknown")));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-command", TextVariables.LABEL, "ai");
|
||||
assertFalse(cmd.execute(user, "island", Collections.singletonList("unknown")));
|
||||
verify(user).sendMessage("general.errors.unknown-command", TextVariables.LABEL, "ai");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgs() {
|
||||
Addon addon = mock(Addon.class);
|
||||
public void testExecuteUserStringListOfStringNoArgsNoPermission() {
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertTrue(cmd.execute(user, "ai", Collections.emptyList()));
|
||||
assertFalse(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.no-permission", "[permission]", "island.home");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIsland() {
|
||||
island = null;
|
||||
Addon addon = mock(Addon.class);
|
||||
public void testExecuteUserStringListOfStringNoArgsSuccess() {
|
||||
when(user.hasPermission(anyString())).thenReturn(true);
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertTrue(cmd.execute(user, "ai", Collections.emptyList()));
|
||||
assertTrue(cmd.execute(user, "island", Collections.emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsConsole() {
|
||||
when(user.isPlayer()).thenReturn(false);
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertFalse(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.use-in-game");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIslandConsole() {
|
||||
when(user.isPlayer()).thenReturn(false);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertFalse(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.use-in-game");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIslandNoPermission() {
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertFalse(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.no-permission", "[permission]", "island.create");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.acidisland.commands.AiCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIslandCreateSuccess() {
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||
when(user.hasPermission(Mockito.eq("island.create"))).thenReturn(true);
|
||||
AiCommand cmd = new AiCommand(addon, "ai");
|
||||
assertTrue(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).getTranslation("commands.island.create.pick");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user