Throw a little testing on toggle logic.

This commit is contained in:
KHobbits 2013-06-08 16:33:30 +01:00
parent a3e6996ef9
commit b8300cc35a
3 changed files with 422 additions and 5 deletions

View File

@ -32,6 +32,8 @@ public class OfflinePlayer implements Player
private final transient UUID uniqueId = UUID.randomUUID(); private final transient UUID uniqueId = UUID.randomUUID();
@Delegate(types = org.bukkit.OfflinePlayer.class) @Delegate(types = org.bukkit.OfflinePlayer.class)
private transient org.bukkit.OfflinePlayer base; private transient org.bukkit.OfflinePlayer base;
private boolean allowFlight = false;
private boolean isFlying = false;
public OfflinePlayer(final String name, final IEssentials ess) public OfflinePlayer(final String name, final IEssentials ess)
{ {
@ -824,13 +826,13 @@ public class OfflinePlayer implements Player
@Override @Override
public void setAllowFlight(boolean bln) public void setAllowFlight(boolean bln)
{ {
throw new UnsupportedOperationException("Not supported yet."); allowFlight = bln;
} }
@Override @Override
public boolean getAllowFlight() public boolean getAllowFlight()
{ {
throw new UnsupportedOperationException("Not supported yet."); return allowFlight;
} }
@Override @Override
@ -1047,13 +1049,13 @@ public class OfflinePlayer implements Player
@Override @Override
public boolean isFlying() public boolean isFlying()
{ {
throw new UnsupportedOperationException("Not supported yet."); return isFlying;
} }
@Override @Override
public void setFlying(boolean arg0) public void setFlying(boolean arg0)
{ {
throw new UnsupportedOperationException("Not supported yet."); isFlying = arg0;
} }
@Override @Override

View File

@ -13,11 +13,16 @@ import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import org.bukkit.help.HelpMap; import org.bukkit.help.HelpMap;
import org.bukkit.inventory.*; import org.bukkit.inventory.*;
import org.bukkit.map.MapView; import org.bukkit.map.MapView;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.ServicesManager; import org.bukkit.plugin.ServicesManager;
@ -632,7 +637,148 @@ public class FakeServer implements Server
@Override @Override
public ConsoleCommandSender getConsoleSender() public ConsoleCommandSender getConsoleSender()
{ {
throw new UnsupportedOperationException("Not supported yet."); return new ConsoleCommandSender() {
@Override
public void sendMessage(String message)
{
System.out.println("Console message: " + message);
}
@Override
public void sendMessage(String[] messages)
{
for (String message : messages) {
System.out.println("Console message: " + message);
}
}
@Override
public Server getServer()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String getName()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isPermissionSet(String name)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isPermissionSet(Permission perm)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean hasPermission(String name)
{
return true;
}
@Override
public boolean hasPermission(Permission perm)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PermissionAttachment addAttachment(Plugin plugin)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, int ticks)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void removeAttachment(PermissionAttachment attachment)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void recalculatePermissions()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Set<PermissionAttachmentInfo> getEffectivePermissions()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isOp()
{
return true;
}
@Override
public void setOp(boolean value)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean isConversing()
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void acceptConversationInput(String input)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public boolean beginConversation(Conversation conversation)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void abandonConversation(Conversation conversation)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details)
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void sendRawMessage(String message)
{
throw new UnsupportedOperationException("Not supported yet.");
}
};
} }
@Override @Override

View File

@ -0,0 +1,269 @@
package com.earth2me.essentials;
import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.NoChargeException;
import java.io.IOException;
import junit.framework.TestCase;
import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.InvalidDescriptionException;
public class ToggleTest extends TestCase
{
private final OfflinePlayer base1;
private final Essentials ess;
private final FakeServer server;
public ToggleTest(String testName)
{
super(testName);
ess = new Essentials();
server = new FakeServer();
server.createWorld("testWorld", Environment.NORMAL);
try
{
ess.setupForTesting(server);
}
catch (InvalidDescriptionException ex)
{
fail("InvalidDescriptionException");
}
catch (IOException ex)
{
fail("IOException");
}
base1 = server.createPlayer("testPlayer1", ess);
server.addPlayer(base1);
ess.getUser(base1);
}
private void runCommand(String command, User user, String[] args) throws Exception
{
IEssentialsCommand cmd;
try
{
cmd = (IEssentialsCommand)Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance();
cmd.setEssentials(ess);
cmd.run(server, user, command, null, args);
}
catch (NoChargeException ex)
{
}
}
private void runConsoleCommand(String command, String[] args) throws Exception
{
IEssentialsCommand cmd;
CommandSender sender = server.getConsoleSender();
try
{
cmd = (IEssentialsCommand)Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance();
cmd.setEssentials(ess);
cmd.run(server, sender, command, null, args);
}
catch (NoChargeException ex)
{
}
}
public void testFlyToggle() throws Exception
{
User user = ess.getUser(base1);
assertFalse(user.getAllowFlight());
runCommand("fly", user, new String[]
{
"on"
});
assertTrue(user.getAllowFlight());
runCommand("fly", user, new String[]
{
"on"
});
assertTrue(user.getAllowFlight());
runCommand("fly", user, new String[]
{
"off"
});
assertFalse(user.getAllowFlight());
runCommand("fly", user, new String[]
{
"off"
});
assertFalse(user.getAllowFlight());
runCommand("fly", user, new String[]
{
});
assertTrue(user.getAllowFlight());
runCommand("fly", user, new String[]
{
});
assertFalse(user.getAllowFlight());
}
public void testFlyDisOnToggle() throws Exception
{
User user = ess.getUser(base1);
user.setAllowFlight(true);
user.setFlying(true);
assertTrue(user.isFlying());
runCommand("fly", user, new String[]
{
});
assertFalse(user.getAllowFlight());
assertFalse(user.isFlying());
}
public void testGodToggle() throws Exception
{
User user = ess.getUser(base1);
assertFalse(user.isGodModeEnabled());
runCommand("god", user, new String[]
{
"on"
});
assertTrue(user.isGodModeEnabled());
runCommand("god", user, new String[]
{
"on"
});
assertTrue(user.isGodModeEnabled());
runCommand("god", user, new String[]
{
"off"
});
assertFalse(user.isGodModeEnabled());
runCommand("god", user, new String[]
{
"off"
});
assertFalse(user.isGodModeEnabled());
runCommand("god", user, new String[]
{
});
assertTrue(user.isGodModeEnabled());
runCommand("god", user, new String[]
{
});
assertFalse(user.isGodModeEnabled());
}
public void testConsoleToggle() throws Exception
{
User user = ess.getUser(base1);
assertFalse(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "on"
});
assertTrue(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "on"
});
assertTrue(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "off"
});
assertFalse(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "off"
});
assertFalse(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName()
});
assertTrue(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName()
});
assertFalse(user.getAllowFlight());
}
public void testAliasesToggle() throws Exception
{
User user = ess.getUser(base1);
assertFalse(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "enable"
});
assertTrue(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "enable"
});
assertTrue(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "disable"
});
assertFalse(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "disable"
});
assertFalse(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "1"
});
assertTrue(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "1"
});
assertTrue(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "0"
});
assertFalse(user.getAllowFlight());
runConsoleCommand("fly", new String[]
{
base1.getName(), "0"
});
assertFalse(user.getAllowFlight());
}
}