summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-06-08 16:33:30 +0100
committerKHobbits <rob@khobbits.co.uk>2013-06-08 16:33:30 +0100
commitb8300cc35a044a46fef73d123d4c9aac61fb57f2 (patch)
treebb1da40c1500bc218f6baa463d4b64e930f038e8
parenta3e6996ef9864d4089453e3afd26bc4c40bcc47d (diff)
downloadEssentials-b8300cc35a044a46fef73d123d4c9aac61fb57f2.tar
Essentials-b8300cc35a044a46fef73d123d4c9aac61fb57f2.tar.gz
Essentials-b8300cc35a044a46fef73d123d4c9aac61fb57f2.tar.lz
Essentials-b8300cc35a044a46fef73d123d4c9aac61fb57f2.tar.xz
Essentials-b8300cc35a044a46fef73d123d4c9aac61fb57f2.zip
Throw a little testing on toggle logic.
-rw-r--r--Essentials/src/com/earth2me/essentials/OfflinePlayer.java10
-rw-r--r--Essentials/test/com/earth2me/essentials/FakeServer.java148
-rw-r--r--Essentials/test/com/earth2me/essentials/ToggleTest.java269
3 files changed, 422 insertions, 5 deletions
diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java
index d78ff7146..0be809f63 100644
--- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java
+++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java
@@ -32,6 +32,8 @@ public class OfflinePlayer implements Player
private final transient UUID uniqueId = UUID.randomUUID();
@Delegate(types = org.bukkit.OfflinePlayer.class)
private transient org.bukkit.OfflinePlayer base;
+ private boolean allowFlight = false;
+ private boolean isFlying = false;
public OfflinePlayer(final String name, final IEssentials ess)
{
@@ -824,13 +826,13 @@ public class OfflinePlayer implements Player
@Override
public void setAllowFlight(boolean bln)
{
- throw new UnsupportedOperationException("Not supported yet.");
+ allowFlight = bln;
}
@Override
public boolean getAllowFlight()
{
- throw new UnsupportedOperationException("Not supported yet.");
+ return allowFlight;
}
@Override
@@ -1047,13 +1049,13 @@ public class OfflinePlayer implements Player
@Override
public boolean isFlying()
{
- throw new UnsupportedOperationException("Not supported yet.");
+ return isFlying;
}
@Override
public void setFlying(boolean arg0)
{
- throw new UnsupportedOperationException("Not supported yet.");
+ isFlying = arg0;
}
@Override
diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java
index dfdf5dfa6..dc7ee9c5d 100644
--- a/Essentials/test/com/earth2me/essentials/FakeServer.java
+++ b/Essentials/test/com/earth2me/essentials/FakeServer.java
@@ -13,11 +13,16 @@ import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand;
+import org.bukkit.conversations.Conversation;
+import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.help.HelpMap;
import org.bukkit.inventory.*;
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.PluginManager;
import org.bukkit.plugin.ServicesManager;
@@ -632,7 +637,148 @@ public class FakeServer implements Server
@Override
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
diff --git a/Essentials/test/com/earth2me/essentials/ToggleTest.java b/Essentials/test/com/earth2me/essentials/ToggleTest.java
new file mode 100644
index 000000000..e5555e9fc
--- /dev/null
+++ b/Essentials/test/com/earth2me/essentials/ToggleTest.java
@@ -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());
+
+ }
+}