mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 00:58:04 +01:00
Added Range command tests and put in some locale messages.
This commit is contained in:
parent
f10c2da7d3
commit
b72d1853b5
@ -89,12 +89,14 @@ commands:
|
|||||||
description: "Sets the island protected range"
|
description: "Sets the island protected range"
|
||||||
invalid-value:
|
invalid-value:
|
||||||
not-numeric: "&c[number] is not a whole number!"
|
not-numeric: "&c[number] is not a whole number!"
|
||||||
too-low: "&cThe protection range must be higher than 1!"
|
too-low: "&cThe protection range must be greater than 1!"
|
||||||
too-high: "&cThe protection range should be less than the island distance!"
|
too-high: "&cThe protection range should be equal or less than [number]!"
|
||||||
same-as-before: "&cThe protection range is already set to [number]!"
|
same-as-before: "&cThe protection range is already set to [number]!"
|
||||||
|
success: "&2Set island protection range to [number]"
|
||||||
reset:
|
reset:
|
||||||
parameters: "<player>"
|
parameters: "<player>"
|
||||||
description: "Resets the island protected range to the server's default"
|
description: "Resets the island protected range to the world default"
|
||||||
|
success: "&2Reset island protection range to [number]"
|
||||||
register:
|
register:
|
||||||
parameters: "<player>"
|
parameters: "<player>"
|
||||||
description: "register player to unowned island you are on"
|
description: "register player to unowned island you are on"
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package us.tastybento.bskyblock.commands.admin.range;
|
package us.tastybento.bskyblock.commands.admin.range;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
|
||||||
import us.tastybento.bskyblock.api.user.User;
|
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||||
|
import us.tastybento.bskyblock.api.localization.TextVariables;
|
||||||
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
|
|
||||||
public class AdminRangeResetCommand extends CompositeCommand {
|
public class AdminRangeResetCommand extends CompositeCommand {
|
||||||
|
|
||||||
public AdminRangeResetCommand(CompositeCommand parent) {
|
public AdminRangeResetCommand(CompositeCommand parent) {
|
||||||
@ -43,8 +44,9 @@ public class AdminRangeResetCommand extends CompositeCommand {
|
|||||||
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
Island island = getIslands().getIsland(getWorld(), targetUUID);
|
||||||
|
|
||||||
// Reset the protection range
|
// Reset the protection range
|
||||||
island.setProtectionRange(getSettings().getIslandProtectionRange());
|
int range = getIWM().getIslandProtectionRange(getWorld());
|
||||||
// TODO send message?
|
island.setProtectionRange(range);
|
||||||
|
user.sendMessage("commands.admin.range.reset.success", TextVariables.NUMBER, String.valueOf(range));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package us.tastybento.bskyblock.commands.admin.range;
|
package us.tastybento.bskyblock.commands.admin.range;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||||
import us.tastybento.bskyblock.api.localization.TextVariables;
|
import us.tastybento.bskyblock.api.localization.TextVariables;
|
||||||
import us.tastybento.bskyblock.api.user.User;
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class AdminRangeSetCommand extends CompositeCommand {
|
public class AdminRangeSetCommand extends CompositeCommand {
|
||||||
|
|
||||||
public AdminRangeSetCommand(CompositeCommand parent) {
|
public AdminRangeSetCommand(CompositeCommand parent) {
|
||||||
@ -57,7 +58,7 @@ public class AdminRangeSetCommand extends CompositeCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (range > island.getRange()) {
|
if (range > island.getRange()) {
|
||||||
user.sendMessage("commands.admin.range.set.invalid-value.too-high", TextVariables.NUMBER, args.get(1));
|
user.sendMessage("commands.admin.range.set.invalid-value.too-high", TextVariables.NUMBER, String.valueOf(island.getRange()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (range == island.getProtectionRange()) {
|
if (range == island.getProtectionRange()) {
|
||||||
@ -67,7 +68,7 @@ public class AdminRangeSetCommand extends CompositeCommand {
|
|||||||
|
|
||||||
// Well, now it can be applied without taking any risks !
|
// Well, now it can be applied without taking any risks !
|
||||||
island.setProtectionRange(range);
|
island.setProtectionRange(range);
|
||||||
// TODO send message?
|
user.sendMessage("commands.admin.range.set.success", TextVariables.NUMBER, String.valueOf(range));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,145 @@
|
|||||||
|
package us.tastybento.bskyblock.commands.admin.range;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
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.mockito.invocation.InvocationOnMock;
|
||||||
|
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 us.tastybento.bskyblock.BSkyBlock;
|
||||||
|
import us.tastybento.bskyblock.Settings;
|
||||||
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
|
import us.tastybento.bskyblock.commands.AdminCommand;
|
||||||
|
import us.tastybento.bskyblock.managers.CommandsManager;
|
||||||
|
import us.tastybento.bskyblock.managers.IslandWorldManager;
|
||||||
|
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||||
|
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||||
|
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||||
|
public class AdminRangeCommandTest {
|
||||||
|
|
||||||
|
private BSkyBlock plugin;
|
||||||
|
private AdminCommand ac;
|
||||||
|
private UUID uuid;
|
||||||
|
private User user;
|
||||||
|
private IslandsManager im;
|
||||||
|
private PlayersManager pm;
|
||||||
|
private UUID notUUID;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws java.lang.Exception
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BSkyBlock.class);
|
||||||
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
|
// Command manager
|
||||||
|
CommandsManager cm = mock(CommandsManager.class);
|
||||||
|
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
Settings s = mock(Settings.class);
|
||||||
|
when(s.getResetWait()).thenReturn(0L);
|
||||||
|
when(s.getResetLimit()).thenReturn(3);
|
||||||
|
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
|
||||||
|
ac = mock(AdminCommand.class);
|
||||||
|
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
|
// Island World Manager
|
||||||
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
|
World world = mock(World.class);
|
||||||
|
when(iwm.getBSBIslandWorld()).thenReturn(world);
|
||||||
|
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||||
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
|
||||||
|
// Player has island to begin with
|
||||||
|
im = mock(IslandsManager.class);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||||
|
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||||
|
when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||||
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
|
// Has team
|
||||||
|
pm = mock(PlayersManager.class);
|
||||||
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
|
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);
|
||||||
|
Answer<String> answer = new Answer<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
return invocation.getArgumentAt(1, String.class);
|
||||||
|
}};
|
||||||
|
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
||||||
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExecuteConsoleNoArgs() {
|
||||||
|
AdminRangeCommand arc = new AdminRangeCommand(ac);
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
|
User console = User.getInstance(sender);
|
||||||
|
arc.execute(console, "", new ArrayList<>());
|
||||||
|
// Show help
|
||||||
|
Mockito.verify(sender).sendMessage("commands.help.header");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExecutePlayerNoArgs() {
|
||||||
|
AdminRangeCommand arc = new AdminRangeCommand(ac);
|
||||||
|
arc.execute(user, "", new ArrayList<>());
|
||||||
|
// Show help"
|
||||||
|
Mockito.verify(user).sendMessage("commands.help.header","[label]","BSkyBlock");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,175 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package us.tastybento.bskyblock.commands.admin.range;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
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.mockito.invocation.InvocationOnMock;
|
||||||
|
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 us.tastybento.bskyblock.BSkyBlock;
|
||||||
|
import us.tastybento.bskyblock.Settings;
|
||||||
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
|
import us.tastybento.bskyblock.commands.AdminCommand;
|
||||||
|
import us.tastybento.bskyblock.managers.CommandsManager;
|
||||||
|
import us.tastybento.bskyblock.managers.IslandWorldManager;
|
||||||
|
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||||
|
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||||
|
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||||
|
public class AdminRangeDisplayCommandTest {
|
||||||
|
|
||||||
|
private BSkyBlock plugin;
|
||||||
|
private AdminCommand ac;
|
||||||
|
private UUID uuid;
|
||||||
|
private User user;
|
||||||
|
private IslandsManager im;
|
||||||
|
private PlayersManager pm;
|
||||||
|
private UUID notUUID;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws java.lang.Exception
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BSkyBlock.class);
|
||||||
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
|
// Command manager
|
||||||
|
CommandsManager cm = mock(CommandsManager.class);
|
||||||
|
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
Settings s = mock(Settings.class);
|
||||||
|
when(s.getResetWait()).thenReturn(0L);
|
||||||
|
when(s.getResetLimit()).thenReturn(3);
|
||||||
|
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
|
||||||
|
ac = mock(AdminCommand.class);
|
||||||
|
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
|
// Island World Manager
|
||||||
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
|
World world = mock(World.class);
|
||||||
|
when(iwm.getBSBIslandWorld()).thenReturn(world);
|
||||||
|
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||||
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
|
||||||
|
// Player has island to begin with
|
||||||
|
im = mock(IslandsManager.class);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||||
|
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||||
|
when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||||
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
|
// Has team
|
||||||
|
pm = mock(PlayersManager.class);
|
||||||
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
|
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);
|
||||||
|
Answer<String> answer = new Answer<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
return invocation.getArgumentAt(1, String.class);
|
||||||
|
}};
|
||||||
|
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
||||||
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeDisplayCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecutePlayerDisplayArgs() {
|
||||||
|
AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac);
|
||||||
|
ardc.execute(user, "display", new ArrayList<>());
|
||||||
|
// Show display
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.display.showing");
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.display.hint");
|
||||||
|
// Run command again
|
||||||
|
ardc.execute(user, "display", new ArrayList<>());
|
||||||
|
// Remove
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.display.hiding");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeDisplayCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecutePlayeShowArgs() {
|
||||||
|
AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac);
|
||||||
|
ardc.execute(user, "show", new ArrayList<>());
|
||||||
|
// Show display
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.display.showing");
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.display.hint");
|
||||||
|
// Run command again
|
||||||
|
ardc.execute(user, "show", new ArrayList<>());
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.display.already-on");
|
||||||
|
ardc.execute(user, "hide", new ArrayList<>());
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.display.hiding");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeDisplayCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecutePlayeHideArgs() {
|
||||||
|
AdminRangeDisplayCommand ardc = new AdminRangeDisplayCommand(ac);
|
||||||
|
ardc.execute(user, "hide", new ArrayList<>());
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.display.already-off");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,206 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package us.tastybento.bskyblock.commands.admin.range;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
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.mockito.invocation.InvocationOnMock;
|
||||||
|
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 us.tastybento.bskyblock.BSkyBlock;
|
||||||
|
import us.tastybento.bskyblock.Settings;
|
||||||
|
import us.tastybento.bskyblock.api.localization.TextVariables;
|
||||||
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
|
import us.tastybento.bskyblock.commands.AdminCommand;
|
||||||
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
|
import us.tastybento.bskyblock.managers.CommandsManager;
|
||||||
|
import us.tastybento.bskyblock.managers.IslandWorldManager;
|
||||||
|
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||||
|
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||||
|
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||||
|
public class AdminRangeResetCommandTest {
|
||||||
|
|
||||||
|
private BSkyBlock plugin;
|
||||||
|
private AdminCommand ac;
|
||||||
|
private UUID uuid;
|
||||||
|
private User user;
|
||||||
|
private IslandsManager im;
|
||||||
|
private PlayersManager pm;
|
||||||
|
private UUID notUUID;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws java.lang.Exception
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BSkyBlock.class);
|
||||||
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
|
// Command manager
|
||||||
|
CommandsManager cm = mock(CommandsManager.class);
|
||||||
|
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
Settings s = mock(Settings.class);
|
||||||
|
when(s.getResetWait()).thenReturn(0L);
|
||||||
|
when(s.getResetLimit()).thenReturn(3);
|
||||||
|
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
|
||||||
|
ac = mock(AdminCommand.class);
|
||||||
|
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
|
// Island World Manager
|
||||||
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
|
World world = mock(World.class);
|
||||||
|
when(iwm.getBSBIslandWorld()).thenReturn(world);
|
||||||
|
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||||
|
when(iwm.getIslandProtectionRange(Mockito.any())).thenReturn(200);
|
||||||
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
|
||||||
|
// Player has island to begin with
|
||||||
|
im = mock(IslandsManager.class);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||||
|
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||||
|
when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||||
|
Island island = mock(Island.class);
|
||||||
|
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
|
// Has team
|
||||||
|
pm = mock(PlayersManager.class);
|
||||||
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
|
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);
|
||||||
|
Answer<String> answer = new Answer<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
return invocation.getArgumentAt(1, String.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
||||||
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeResetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteConsoleNoArgs() {
|
||||||
|
AdminRangeResetCommand arc = new AdminRangeResetCommand(ac);
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
|
User console = User.getInstance(sender);
|
||||||
|
arc.execute(console, "", new ArrayList<>());
|
||||||
|
// Show help
|
||||||
|
Mockito.verify(sender).sendMessage("commands.help.header");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeResetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecutePlayerNoArgs() {
|
||||||
|
AdminRangeResetCommand arc = new AdminRangeResetCommand(ac);
|
||||||
|
arc.execute(user, "", new ArrayList<>());
|
||||||
|
// Show help
|
||||||
|
Mockito.verify(user).sendMessage("commands.help.header","[label]","BSkyBlock");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeResetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteUnknownPlayer() {
|
||||||
|
AdminRangeResetCommand arc = new AdminRangeResetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("general.errors.unknown-player");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeResetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteKnownPlayerNoIsland() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||||
|
AdminRangeResetCommand arc = new AdminRangeResetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("general.errors.player-has-no-island");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeResetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteKnownPlayer() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
AdminRangeResetCommand arc = new AdminRangeResetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.reset.success", TextVariables.NUMBER, "200");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,295 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package us.tastybento.bskyblock.commands.admin.range;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
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.mockito.invocation.InvocationOnMock;
|
||||||
|
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 us.tastybento.bskyblock.BSkyBlock;
|
||||||
|
import us.tastybento.bskyblock.Settings;
|
||||||
|
import us.tastybento.bskyblock.api.localization.TextVariables;
|
||||||
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
|
import us.tastybento.bskyblock.commands.AdminCommand;
|
||||||
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
|
import us.tastybento.bskyblock.managers.CommandsManager;
|
||||||
|
import us.tastybento.bskyblock.managers.IslandWorldManager;
|
||||||
|
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||||
|
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||||
|
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tastybento
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||||
|
public class AdminRangeSetCommandTest {
|
||||||
|
|
||||||
|
private BSkyBlock plugin;
|
||||||
|
private AdminCommand ac;
|
||||||
|
private UUID uuid;
|
||||||
|
private User user;
|
||||||
|
private IslandsManager im;
|
||||||
|
private PlayersManager pm;
|
||||||
|
private UUID notUUID;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws java.lang.Exception
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BSkyBlock.class);
|
||||||
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
|
// Command manager
|
||||||
|
CommandsManager cm = mock(CommandsManager.class);
|
||||||
|
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
Settings s = mock(Settings.class);
|
||||||
|
when(s.getResetWait()).thenReturn(0L);
|
||||||
|
when(s.getResetLimit()).thenReturn(3);
|
||||||
|
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
|
||||||
|
ac = mock(AdminCommand.class);
|
||||||
|
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||||
|
|
||||||
|
// Island World Manager
|
||||||
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||||
|
World world = mock(World.class);
|
||||||
|
when(iwm.getBSBIslandWorld()).thenReturn(world);
|
||||||
|
when(iwm.getFriendlyName(Mockito.any())).thenReturn("BSkyBlock");
|
||||||
|
when(iwm.getIslandProtectionRange(Mockito.any())).thenReturn(200);
|
||||||
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
|
|
||||||
|
|
||||||
|
// Player has island to begin with
|
||||||
|
im = mock(IslandsManager.class);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||||
|
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||||
|
when(im.getTeamLeader(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||||
|
Island island = mock(Island.class);
|
||||||
|
when(island.getRange()).thenReturn(50);
|
||||||
|
when(island.getProtectionRange()).thenReturn(50);
|
||||||
|
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||||
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
|
// Has team
|
||||||
|
pm = mock(PlayersManager.class);
|
||||||
|
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
|
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);
|
||||||
|
Answer<String> answer = new Answer<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
return invocation.getArgumentAt(1, String.class);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer(answer );
|
||||||
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteConsoleNoArgs() {
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
CommandSender sender = mock(CommandSender.class);
|
||||||
|
User console = User.getInstance(sender);
|
||||||
|
arc.execute(console, "", new ArrayList<>());
|
||||||
|
// Show help
|
||||||
|
Mockito.verify(sender).sendMessage("commands.help.header");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecutePlayerNoArgs() {
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
arc.execute(user, "", new ArrayList<>());
|
||||||
|
// Show help
|
||||||
|
Mockito.verify(user).sendMessage("commands.help.header","[label]","BSkyBlock");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteUnknownPlayer() {
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("100");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("general.errors.unknown-player");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteKnownPlayerNoIsland() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("100");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("general.errors.player-has-no-island");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteTooHigh() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("100");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.too-high", TextVariables.NUMBER, "50");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteNotANumber() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("NAN");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, "NAN");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteDoubleNumber() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("3.141592654");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, "3.141592654");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteZero() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("0");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.too-low", TextVariables.NUMBER, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteNegNumber() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("-437645");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.not-numeric", TextVariables.NUMBER, "-437645");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecuteSame() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("50");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.set.invalid-value.same-as-before", TextVariables.NUMBER, "50");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link us.tastybento.bskyblock.commands.admin.range.AdminRangeSetCommand#execute(us.tastybento.bskyblock.api.user.User, java.lang.String, java.util.List)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testExecute() {
|
||||||
|
when(pm.getUUID(Mockito.anyString())).thenReturn(uuid);
|
||||||
|
AdminRangeSetCommand arc = new AdminRangeSetCommand(ac);
|
||||||
|
List<String> args = new ArrayList<>();
|
||||||
|
args.add("tastybento");
|
||||||
|
args.add("48");
|
||||||
|
arc.execute(user, "", args);
|
||||||
|
Mockito.verify(user).sendMessage("commands.admin.range.set.success", TextVariables.NUMBER, "48");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user