Add set to the jail time command and unit test it.

This commit is contained in:
graywolf336 2015-02-20 23:10:05 -06:00
parent 1c3ad5b75a
commit 88cc080f60
3 changed files with 77 additions and 2 deletions

View File

@ -142,7 +142,7 @@ public class PrisonerManager {
* @param player who is the prisoner
* @param prisoner data containing everything pertaining to them
*/
public void jailPrisoner(Jail jail, Cell cell, Player player, Prisoner prisoner) {
protected void jailPrisoner(Jail jail, Cell cell, Player player, Prisoner prisoner) {
//If they have handcuffs on them, then let's remove them before we continue
//this way the handcuff listeners and this aren't battleing each other
if(pl.getHandCuffManager().isHandCuffed(player.getUniqueId())) {

View File

@ -15,7 +15,7 @@ import com.graywolf336.jail.enums.Lang;
needsPlayer = false,
pattern = "time|t",
permission = "jail.command.jailtime",
usage = "/jail time [add|remove|show] [name] <time>"
usage = "/jail time [add|remove|set|show] [name] <time>"
)
public class JailTimeCommand implements Command {
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
@ -35,6 +35,8 @@ public class JailTimeCommand implements Command {
p.addTime(Util.getTime(args[3]));
}else if(args[1].equalsIgnoreCase("remove")) {
p.subtractTime(Util.getTime(args[3]));
}else if(args[1].equalsIgnoreCase("set")) {
p.setRemainingTime(Util.getTime(args[3]));
}else {
return false;
}

View File

@ -0,0 +1,73 @@
package test.java.com.graywolf336.jail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginDescriptionFile;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import test.java.com.graywolf336.jail.util.TestInstanceCreator;
import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.Util;
import com.graywolf336.jail.beans.Prisoner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ JailMain.class, PluginDescriptionFile.class })
public class TestJailCommands {
private static TestInstanceCreator creator;
private static JailMain main;
private static final String name = "TestJailCommands";
@BeforeClass
public static void setUp() throws Exception {
creator = new TestInstanceCreator();
assertNotNull("The instance creator is null.", creator);
assertTrue(creator.setup());
main = creator.getMain();
assertNotNull("The JailMain class is null.", main);
assertTrue("The adding of a jail failed.", creator.addJail(name));
assertTrue("The jail " + name + " is not a valid jail.", main.getJailManager().isValidJail(name));
}
@AfterClass
public static void tearDown() throws Exception {
creator.tearDown();
main = null;
}
@Test
public void testJailTimeCommand() throws Exception {
Long time = Util.getTime("30m");
assertEquals("The util didn't return the proper time.", 1800000L, time, 0);
Prisoner p = new Prisoner(creator.getPlayer().getUniqueId().toString(), creator.getPlayer().getName(), true, time, "UnitTeting", "Testing out the jail time command.");
main.getPrisonerManager().prepareJail(main.getJailManager().getJail(name), null, creator.getPlayer(), p);
assertTrue("The player " + creator.getPlayer().getName() + " is not jailed, checked by UUID.", main.getJailManager().isPlayerJailed(creator.getPlayer().getUniqueId()));
assertTrue("The player " + creator.getPlayer().getName() + " is not jailed, checked by username.", main.getJailManager().isPlayerJailedByLastKnownUsername(creator.getPlayer().getName()));
//jail time show graywolf336
assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "show", creator.getPlayer().getName() }));
verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 30 minutes remaining.");
//jail time add graywolf336 30m
assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "add", creator.getPlayer().getName(), "30m" }));
verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 60 minutes remaining.");
//jail time remove graywolf336 10m
assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "remove", creator.getPlayer().getName(), "10m" }));
verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 50 minutes remaining.");
//jail time set graywolf336 25m
assertTrue("The command failed.", main.onCommand(creator.getCommandSender(), null, "jail", new String[] { "time", "set", creator.getPlayer().getName(), "25m" }));
verify(creator.getCommandSender(), atLeast(1)).sendMessage(ChatColor.DARK_GREEN + "graywolf336 has 25 minutes remaining.");
}
}