From 21f7b0d4688f611d1b10e5d8e134dff2dc666356 Mon Sep 17 00:00:00 2001 From: DoNotSpamPls <7570108+DoNotSpamPls@users.noreply.github.com> Date: Wed, 9 Jan 2019 11:07:04 +0200 Subject: [PATCH] Remove outdated permission plugin handlers, minor test fixes --- .../messaging/SimpleMessageRecipient.java | 1 - .../essentials/perm/PermissionsHandler.java | 9 +- .../perm/impl/AbstractVaultHandler.java | 4 +- .../perm/impl/BPermissions2Handler.java | 17 -- .../perm/impl/PermissionsExHandler.java | 16 -- .../perm/impl/PrivilegesHandler.java | 16 -- .../perm/impl/SimplyPermsHandler.java | 16 -- .../essentials/register/payment/Method.java | 4 +- .../essentials/register/payment/Methods.java | 18 +- .../register/payment/methods/VaultEco.java | 6 +- .../com/earth2me/essentials/EconomyTest.java | 81 ++++----- .../com/earth2me/essentials/FakeServer.java | 41 +++-- .../earth2me/essentials/MessagingTest.java | 6 +- .../com/earth2me/essentials/StorageTest.java | 14 +- .../com/earth2me/essentials/ToggleTest.java | 6 +- .../com/earth2me/essentials/UtilTest.java | 172 +++++++++--------- 16 files changed, 171 insertions(+), 256 deletions(-) delete mode 100644 Essentials/src/com/earth2me/essentials/perm/impl/BPermissions2Handler.java delete mode 100644 Essentials/src/com/earth2me/essentials/perm/impl/PermissionsExHandler.java delete mode 100644 Essentials/src/com/earth2me/essentials/perm/impl/PrivilegesHandler.java delete mode 100644 Essentials/src/com/earth2me/essentials/perm/impl/SimplyPermsHandler.java diff --git a/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java b/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java index b5a2fb7dc..445f1f759 100644 --- a/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java +++ b/Essentials/src/com/earth2me/essentials/messaging/SimpleMessageRecipient.java @@ -2,7 +2,6 @@ package com.earth2me.essentials.messaging; import static com.earth2me.essentials.I18n.tl; -import com.earth2me.essentials.Console; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.IUser; import com.earth2me.essentials.User; diff --git a/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java b/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java index 11b32787f..92510cf6b 100644 --- a/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/PermissionsHandler.java @@ -13,7 +13,7 @@ public class PermissionsHandler implements IPermissionsHandler { private transient IPermissionsHandler handler = null; private transient String defaultGroup = "default"; private final transient Essentials ess; - private transient boolean useSuperperms = false; + private transient boolean useSuperperms; private Class lastHandler = null; @@ -92,10 +92,6 @@ public class PermissionsHandler implements IPermissionsHandler { public void checkPermissions() { // load and assign a handler List> providerClazz = Arrays.asList( - BPermissions2Handler.class, - PermissionsExHandler.class, - PrivilegesHandler.class, - SimplyPermsHandler.class, GenericVaultHandler.class, SuperpermsHandler.class ); @@ -158,7 +154,4 @@ public class PermissionsHandler implements IPermissionsHandler { } } - private void checkPermLag(long start) { - checkPermLag(start, "not defined"); - } } diff --git a/Essentials/src/com/earth2me/essentials/perm/impl/AbstractVaultHandler.java b/Essentials/src/com/earth2me/essentials/perm/impl/AbstractVaultHandler.java index b046a0df2..b2d381cdf 100644 --- a/Essentials/src/com/earth2me/essentials/perm/impl/AbstractVaultHandler.java +++ b/Essentials/src/com/earth2me/essentials/perm/impl/AbstractVaultHandler.java @@ -13,7 +13,7 @@ public abstract class AbstractVaultHandler extends SuperpermsHandler { protected static Permission perms = null; protected static Chat chat = null; - public boolean setupProviders() { + private boolean setupProviders() { try { Class.forName("net.milkbowl.vault.permission.Permission"); Class.forName("net.milkbowl.vault.chat.Chat"); @@ -65,7 +65,7 @@ public abstract class AbstractVaultHandler extends SuperpermsHandler { } } - protected boolean canLoad() { + boolean canLoad() { if (Bukkit.getPluginManager().getPlugin("Vault") == null) return false; try { return setupProviders(); diff --git a/Essentials/src/com/earth2me/essentials/perm/impl/BPermissions2Handler.java b/Essentials/src/com/earth2me/essentials/perm/impl/BPermissions2Handler.java deleted file mode 100644 index c89c5da5d..000000000 --- a/Essentials/src/com/earth2me/essentials/perm/impl/BPermissions2Handler.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.earth2me.essentials.perm.impl; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - - -public class BPermissions2Handler extends AbstractVaultHandler { - @Override - public boolean canBuild(final Player base, final String group) { - return hasPermission(base, "bPermissions.build"); - } - - @Override - public boolean tryProvider() { - return super.canLoad() && Bukkit.getPluginManager().getPlugin("bPermissions") != null; - } -} diff --git a/Essentials/src/com/earth2me/essentials/perm/impl/PermissionsExHandler.java b/Essentials/src/com/earth2me/essentials/perm/impl/PermissionsExHandler.java deleted file mode 100644 index a760e88ee..000000000 --- a/Essentials/src/com/earth2me/essentials/perm/impl/PermissionsExHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.earth2me.essentials.perm.impl; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class PermissionsExHandler extends AbstractVaultHandler { - @Override - public boolean canBuild(final Player base, final String group) { - return base != null && chat.getPlayerInfoBoolean(base.getWorld().getName(), base, "build", false); - } - - @Override - public boolean tryProvider() { - return super.canLoad() && Bukkit.getPluginManager().getPlugin("PermissionsEx") != null; - } -} diff --git a/Essentials/src/com/earth2me/essentials/perm/impl/PrivilegesHandler.java b/Essentials/src/com/earth2me/essentials/perm/impl/PrivilegesHandler.java deleted file mode 100644 index 8fdd79188..000000000 --- a/Essentials/src/com/earth2me/essentials/perm/impl/PrivilegesHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.earth2me.essentials.perm.impl; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class PrivilegesHandler extends AbstractVaultHandler { - @Override - public boolean canBuild(Player base, String group) { - return hasPermission(base, "privileges.build"); - } - - @Override - public boolean tryProvider() { - return super.canLoad() && Bukkit.getPluginManager().getPlugin("Privileges") != null; - } -} diff --git a/Essentials/src/com/earth2me/essentials/perm/impl/SimplyPermsHandler.java b/Essentials/src/com/earth2me/essentials/perm/impl/SimplyPermsHandler.java deleted file mode 100644 index ee289eb47..000000000 --- a/Essentials/src/com/earth2me/essentials/perm/impl/SimplyPermsHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.earth2me.essentials.perm.impl; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -public class SimplyPermsHandler extends AbstractVaultHandler { - @Override - public boolean canBuild(Player base, String group) { - return hasPermission(base, "permissions.allow.build"); - } - - @Override - public boolean tryProvider() { - return super.canLoad() && Bukkit.getPluginManager().getPlugin("SimplyPerms") != null; - } -} diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Method.java b/Essentials/src/com/earth2me/essentials/register/payment/Method.java index 3d2f62bdb..d977e5961 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Method.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Method.java @@ -5,10 +5,10 @@ import org.bukkit.plugin.Plugin; /** * Interface to be implemented by a payment method. + * Copyright (C) 2011 + * AOL license * * @author Nijikokun (@nijikokun) - * @copyright Copyright (C) 2011 - * @license AOL license */ public interface Method { /** diff --git a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java index 9316da190..458501ef1 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/Methods.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/Methods.java @@ -22,7 +22,7 @@ import java.util.Set; * preferred: "iConomy" * * - * @author: Nijikokun (@nijikokun) @copyright: Copyright (C) 2011 @license: AOL license + * @author Nijikokun (@nijikokun) @copyright: Copyright (C) 2011 @license: AOL license * */ public class Methods { @@ -30,9 +30,9 @@ public class Methods { private static boolean self = false; private static Method Method = null; private static String preferred = ""; - private static final Set Methods = new HashSet(); - private static final Set Dependencies = new HashSet(); - private static final Set Attachables = new HashSet(); + private static final Set Methods = new HashSet<>(); + private static final Set Dependencies = new HashSet<>(); + private static final Set Attachables = new HashSet<>(); static { _init(); @@ -79,7 +79,7 @@ public class Methods { * * @return Set - Array of payment methods that are loaded. * - * @see #setMethod(org.bukkit.plugin.Plugin) + * @see #setMethod(PluginManager) */ public static Set getDependencies() { return Dependencies; @@ -114,8 +114,8 @@ public class Methods { * * @return boolean * - * @see #setMethod(org.bukkit.plugin.Plugin) - * @see #checkDisabled(org.bukkit.plugin.Plugin) + * @see #setMethod(PluginManager) + * @see #checkDisabled(Plugin) */ public static boolean hasMethod() { return (Method != null); @@ -124,7 +124,7 @@ public class Methods { /** * Checks Plugin Class against a multitude of checks to verify it's usability as a payment method. * - * @param PluginManager the plugin manager for the server + * @param manager the plugin manager for the server * * @return boolean True on success, False on failure. */ @@ -140,7 +140,7 @@ public class Methods { int count = 0; boolean match = false; - Plugin plugin = null; + Plugin plugin; for (String name : getDependencies()) { if (hasMethod()) { diff --git a/Essentials/src/com/earth2me/essentials/register/payment/methods/VaultEco.java b/Essentials/src/com/earth2me/essentials/register/payment/methods/VaultEco.java index b7833d8c1..dc9af2f92 100644 --- a/Essentials/src/com/earth2me/essentials/register/payment/methods/VaultEco.java +++ b/Essentials/src/com/earth2me/essentials/register/payment/methods/VaultEco.java @@ -109,9 +109,7 @@ public class VaultEco implements Method { try { RegisteredServiceProvider ecoPlugin = plugin.getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class); return plugin instanceof Vault && ecoPlugin != null && !ecoPlugin.getProvider().getName().equals("Essentials Economy"); - } catch (LinkageError e) { - return false; - } catch (Exception e) { + } catch (LinkageError | Exception e) { return false; } } @@ -130,7 +128,7 @@ public class VaultEco implements Method { private final String name; private final Economy economy; - public VaultAccount(String name, Economy economy) { + VaultAccount(String name, Economy economy) { this.name = name; this.economy = economy; } diff --git a/Essentials/test/com/earth2me/essentials/EconomyTest.java b/Essentials/test/com/earth2me/essentials/EconomyTest.java index ce4be0f08..82c528e7e 100644 --- a/Essentials/test/com/earth2me/essentials/EconomyTest.java +++ b/Essentials/test/com/earth2me/essentials/EconomyTest.java @@ -5,34 +5,33 @@ import com.earth2me.essentials.api.UserDoesNotExistException; import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.NoChargeException; -import junit.framework.TestCase; import net.ess3.api.Economy; import org.bukkit.World.Environment; import org.bukkit.command.CommandSender; import org.bukkit.plugin.InvalidDescriptionException; +import org.junit.Assert; import org.junit.Test; import java.io.IOException; -public class EconomyTest extends TestCase { +public class EconomyTest { private final transient Essentials ess; private static final String NPCNAME = "npc1"; private static final String PLAYERNAME = "testPlayer1"; private static final String PLAYERNAME2 = "testPlayer2"; private final FakeServer server; - public EconomyTest(final String testName) { - super(testName); + public EconomyTest() { this.server = new FakeServer(); server.createWorld("testWorld", Environment.NORMAL); ess = new Essentials(server); try { ess.setupForTesting(server); } catch (InvalidDescriptionException ex) { - fail("InvalidDescriptionException"); + Assert.fail("InvalidDescriptionException"); } catch (IOException ex) { - fail("IOException"); + Assert.fail("IOException"); } server.addPlayer(new OfflinePlayer(PLAYERNAME, ess.getServer())); server.addPlayer(new OfflinePlayer(PLAYERNAME2, ess.getServer())); @@ -42,66 +41,63 @@ public class EconomyTest extends TestCase { @Test public void testEconomy() { // test NPC - assertFalse("NPC does not exists", Economy.playerExists(NPCNAME)); - assertTrue("Create NPC", Economy.createNPC(NPCNAME)); - assertTrue("NPC exists", Economy.playerExists(NPCNAME)); - assertNotNull("NPC can be accessed", ess.getOfflineUser(NPCNAME)); + Assert.assertFalse("NPC does not exists", Economy.playerExists(NPCNAME)); + Assert.assertTrue("Create NPC", Economy.createNPC(NPCNAME)); + Assert.assertTrue("NPC exists", Economy.playerExists(NPCNAME)); + Assert.assertNotNull("NPC can be accessed", ess.getOfflineUser(NPCNAME)); try { Economy.removeNPC(NPCNAME); } catch (UserDoesNotExistException ex) { - fail(ex.getMessage()); + Assert.fail(ex.getMessage()); } - assertFalse("NPC can be removed", Economy.playerExists(NPCNAME)); + Assert.assertFalse("NPC can be removed", Economy.playerExists(NPCNAME)); //test Math try { - assertTrue("Player exists", Economy.playerExists(PLAYERNAME)); + Assert.assertTrue("Player exists", Economy.playerExists(PLAYERNAME)); Economy.resetBalance(PLAYERNAME); - assertEquals("Player has no money", 0.0, Economy.getMoney(PLAYERNAME)); + Assert.assertEquals("Player has no money", 0.0, Economy.getMoney(PLAYERNAME), 0); Economy.add(PLAYERNAME, 10.0); - assertEquals("Add money", 10.0, Economy.getMoney(PLAYERNAME)); + Assert.assertEquals("Add money", 10.0, Economy.getMoney(PLAYERNAME),0); Economy.subtract(PLAYERNAME, 5.0); - assertEquals("Subtract money", 5.0, Economy.getMoney(PLAYERNAME)); + Assert.assertEquals("Subtract money", 5.0, Economy.getMoney(PLAYERNAME),0); Economy.multiply(PLAYERNAME, 2.0); - assertEquals("Multiply money", 10.0, Economy.getMoney(PLAYERNAME)); + Assert.assertEquals("Multiply money", 10.0, Economy.getMoney(PLAYERNAME),0); Economy.divide(PLAYERNAME, 2.0); - assertEquals("Divide money", 5.0, Economy.getMoney(PLAYERNAME)); + Assert.assertEquals("Divide money", 5.0, Economy.getMoney(PLAYERNAME),0); Economy.setMoney(PLAYERNAME, 10.0); - assertEquals("Set money", 10.0, Economy.getMoney(PLAYERNAME)); - } catch (NoLoanPermittedException ex) { - fail(ex.getMessage()); - } catch (UserDoesNotExistException ex) { - fail(ex.getMessage()); + Assert.assertEquals("Set money", 10.0, Economy.getMoney(PLAYERNAME),0); + } catch (NoLoanPermittedException | UserDoesNotExistException ex) { + Assert.fail(ex.getMessage()); } //test Format - assertEquals("Format $1,000", "$1,000", Economy.format(1000.0)); - assertEquals("Format $10", "$10", Economy.format(10.0)); - assertEquals("Format $10.10", "$10.10", Economy.format(10.10)); - assertEquals("Format $10.10", "$10.10", Economy.format(10.1000001)); - assertEquals("Format $10.10", "$10.10", Economy.format(10.1099999)); + Assert.assertEquals("Format $1,000", "$1,000", Economy.format(1000.0)); + Assert.assertEquals("Format $10", "$10", Economy.format(10.0)); + Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.10)); + Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.1000001)); + Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.1099999)); //test Exceptions try { - assertTrue("Player exists", Economy.playerExists(PLAYERNAME)); + Assert.assertTrue("Player exists", Economy.playerExists(PLAYERNAME)); Economy.resetBalance(PLAYERNAME); - assertEquals("Reset balance", 0.0, Economy.getMoney(PLAYERNAME)); + Assert.assertEquals("Reset balance", 0.0, Economy.getMoney(PLAYERNAME),0); Economy.subtract(PLAYERNAME, 5.0); - fail("Did not throw exception"); - } catch (NoLoanPermittedException ex) { + Assert.fail("Did not throw exception"); + } catch (NoLoanPermittedException ignored) { } catch (UserDoesNotExistException ex) { - fail(ex.getMessage()); + Assert.fail(ex.getMessage()); } try { Economy.resetBalance("UnknownPlayer"); - fail("Did not throw exception"); + Assert.fail("Did not throw exception"); } catch (NoLoanPermittedException ex) { - fail(ex.getMessage()); - } catch (UserDoesNotExistException ex) { - } + Assert.fail(ex.getMessage()); + } catch (UserDoesNotExistException ignored) {} } private void runCommand(String command, User user, String args) throws Exception { @@ -116,8 +112,7 @@ public class EconomyTest extends TestCase { .loadClass("com.earth2me.essentials.commands.Command" + command).newInstance(); cmd.setEssentials(ess); cmd.run(server, user, command, null, args); - } catch (NoChargeException ex) { - } + } catch (NoChargeException ignored) {} } @@ -135,16 +130,16 @@ public class EconomyTest extends TestCase { .loadClass("com.earth2me.essentials.commands.Command" + command).newInstance(); cmd.setEssentials(ess); cmd.run(server, new CommandSource(sender), command, null, args); - } catch (NoChargeException ex) { - } + } catch (NoChargeException ignored) {} } - public void testNegativePayCommand() throws Exception { + @Test + public void testNegativePayCommand() { User user1 = ess.getUser(PLAYERNAME); try { runCommand("pay", user1, PLAYERNAME2 + " -123"); } catch (Exception e) { - assertEquals(I18n.tl("payMustBePositive"), e.getMessage()); + Assert.assertEquals(I18n.tl("payMustBePositive"), e.getMessage()); } } } diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java index 88967df81..35ec5a193 100644 --- a/Essentials/test/com/earth2me/essentials/FakeServer.java +++ b/Essentials/test/com/earth2me/essentials/FakeServer.java @@ -39,7 +39,6 @@ import org.bukkit.util.CachedServerIcon; import java.awt.image.BufferedImage; import java.io.File; -import java.io.UnsupportedEncodingException; import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.Future; @@ -48,11 +47,11 @@ import java.util.logging.Logger; public class FakeServer implements Server { - private List players = new ArrayList(); - private final List worlds = new ArrayList(); - PluginManager pluginManager = new FakePluginManager(); + private List players = new ArrayList<>(); + private final List worlds = new ArrayList<>(); + private PluginManager pluginManager = new FakePluginManager(); - public FakeServer() { + FakeServer() { if (Bukkit.getServer() == null) { Bukkit.setServer(this); } @@ -139,7 +138,7 @@ public class FakeServer implements Server { @Override public List matchPlayer(String string) { - List matches = new ArrayList(); + List matches = new ArrayList<>(); for (Player player : players) { if (player.getName().substring(0, Math.min(player.getName().length(), string.length())).equalsIgnoreCase(string)) { matches.add(player); @@ -390,12 +389,12 @@ public class FakeServer implements Server { throw new UnsupportedOperationException("Not supported yet."); } - public void addPlayer(Player base1) { + void addPlayer(Player base1) { players.add(base1); pluginManager.callEvent(new PlayerJoinEvent(base1, null)); } - public OfflinePlayer createPlayer(String name) { + OfflinePlayer createPlayer(String name) { OfflinePlayer player = new OfflinePlayer(name, this); player.setLocation(new Location(worlds.get(0), 0, 0, 0, 0, 0)); return player; @@ -589,14 +588,15 @@ public class FakeServer implements Server { @Override public UUID getUniqueId() { - if (string == "testPlayer1") { - return UUID.fromString("3c9ebe1a-9098-43fd-bc0c-a369b76817ba"); - } else if (string == "testPlayer2") { - return UUID.fromString("2c9ebe1a-9098-43fd-bc0c-a369b76817ba"); - } else if (string == "npc1") { - return null; + switch (string) { + case "testPlayer1": + return UUID.fromString("3c9ebe1a-9098-43fd-bc0c-a369b76817ba"); + case "testPlayer2": + return UUID.fromString("2c9ebe1a-9098-43fd-bc0c-a369b76817ba"); + case "npc1": + return null; } - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + throw new UnsupportedOperationException("Not supported yet."); } }; } @@ -754,7 +754,7 @@ public class FakeServer implements Server { } @Override - public Set getOperators() { + public Set getOperators() { throw new UnsupportedOperationException("Not supported yet."); } @@ -919,12 +919,12 @@ public class FakeServer implements Server { } @Override - public CachedServerIcon loadServerIcon(File file) throws Exception { + public CachedServerIcon loadServerIcon(File file) { throw new UnsupportedOperationException("Not supported yet."); } @Override - public CachedServerIcon loadServerIcon(BufferedImage bufferedImage) throws Exception { + public CachedServerIcon loadServerIcon(BufferedImage bufferedImage) { throw new UnsupportedOperationException("Not supported yet."); } @@ -969,6 +969,7 @@ public class FakeServer implements Server { } @Override + @SuppressWarnings("deprecation") public UnsafeValues getUnsafe() { throw new UnsupportedOperationException("Not supported yet."); } @@ -1050,7 +1051,7 @@ public class FakeServer implements Server { } class FakePluginManager implements PluginManager { - ArrayList listeners = new ArrayList(); + ArrayList listeners = new ArrayList<>(); @Override public void registerInterface(Class loader) throws IllegalArgumentException { @@ -1078,7 +1079,7 @@ public class FakeServer implements Server { } @Override - public Plugin loadPlugin(File file) throws InvalidPluginException, InvalidDescriptionException, UnknownDependencyException { + public Plugin loadPlugin(File file) throws UnknownDependencyException { throw new UnsupportedOperationException("Not supported yet."); } diff --git a/Essentials/test/com/earth2me/essentials/MessagingTest.java b/Essentials/test/com/earth2me/essentials/MessagingTest.java index 4d8dcc387..b90b9ea21 100644 --- a/Essentials/test/com/earth2me/essentials/MessagingTest.java +++ b/Essentials/test/com/earth2me/essentials/MessagingTest.java @@ -49,8 +49,7 @@ public class MessagingTest { .loadClass("com.earth2me.essentials.commands.Command" + command).newInstance(); cmd.setEssentials(ess); cmd.run(server, user, command, null, args); - } catch (NoChargeException ex) { - } + } catch (NoChargeException ignored) {} } @@ -68,8 +67,7 @@ public class MessagingTest { .loadClass("com.earth2me.essentials.commands.Command" + command).newInstance(); cmd.setEssentials(ess); cmd.run(server, new CommandSource(sender), command, null, args); - } catch (NoChargeException ex) { - } + } catch (NoChargeException ignored) {} } @Test(expected = Exception.class) // I really don't like this, but see note below about console reply diff --git a/Essentials/test/com/earth2me/essentials/StorageTest.java b/Essentials/test/com/earth2me/essentials/StorageTest.java index 8dd82ce50..3a10abcab 100644 --- a/Essentials/test/com/earth2me/essentials/StorageTest.java +++ b/Essentials/test/com/earth2me/essentials/StorageTest.java @@ -1,19 +1,19 @@ package com.earth2me.essentials; -import junit.framework.TestCase; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.plugin.InvalidDescriptionException; +import org.junit.Assert; import org.junit.Test; import java.io.IOException; -public class StorageTest extends TestCase { - Essentials ess; - FakeServer server; - World world; +public class StorageTest { + private Essentials ess; + private FakeServer server; + private World world; public StorageTest() { server = new FakeServer(); @@ -22,9 +22,9 @@ public class StorageTest extends TestCase { try { ess.setupForTesting(server); } catch (InvalidDescriptionException ex) { - fail("InvalidDescriptionException"); + Assert.fail("InvalidDescriptionException"); } catch (IOException ex) { - fail("IOException"); + Assert.fail("IOException"); } } diff --git a/Essentials/test/com/earth2me/essentials/ToggleTest.java b/Essentials/test/com/earth2me/essentials/ToggleTest.java index 330ac7ccb..7250ce566 100644 --- a/Essentials/test/com/earth2me/essentials/ToggleTest.java +++ b/Essentials/test/com/earth2me/essentials/ToggleTest.java @@ -39,8 +39,7 @@ public class ToggleTest extends TestCase { 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) { - } + } catch (NoChargeException ignored) {} } @@ -53,8 +52,7 @@ public class ToggleTest extends TestCase { cmd = (IEssentialsCommand) Essentials.class.getClassLoader().loadClass("com.earth2me.essentials.commands.Command" + command).newInstance(); cmd.setEssentials(ess); cmd.run(server, new CommandSource(sender), command, null, args); - } catch (NoChargeException ex) { - } + } catch (NoChargeException ignored) {} } diff --git a/Essentials/test/com/earth2me/essentials/UtilTest.java b/Essentials/test/com/earth2me/essentials/UtilTest.java index da58aa9fe..cd905f9ad 100644 --- a/Essentials/test/com/earth2me/essentials/UtilTest.java +++ b/Essentials/test/com/earth2me/essentials/UtilTest.java @@ -15,13 +15,11 @@ import java.util.Set; public class UtilTest extends TestCase { - private final Essentials ess; - private final FakeServer server; public UtilTest() { - server = new FakeServer(); + FakeServer server = new FakeServer(); server.createWorld("testWorld", Environment.NORMAL); - ess = new Essentials(server); + Essentials ess = new Essentials(server); try { ess.setupForTesting(server); } catch (InvalidDescriptionException ex) { @@ -32,7 +30,7 @@ public class UtilTest extends TestCase { } public void testSafeLocation() { - Set testSet = new HashSet(); + Set testSet = new HashSet<>(); int count = 0; int x, y, z, origX, origY, origZ; x = y = z = origX = origY = origZ = 0; @@ -63,132 +61,132 @@ public class UtilTest extends TestCase { public void testFDDfuture() { Calendar a, b; - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 10, 0, 1); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 1); assertEquals("1 second", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 10, 0, 2); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 2); assertEquals("2 seconds", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 10, 0, 3); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 3); assertEquals("3 seconds", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 10, 1, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 1, 0); assertEquals("1 minute", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 10, 2, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 2, 0); assertEquals("2 minutes", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 10, 3, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 3, 0); assertEquals("3 minutes", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 11, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 11, 0, 0); assertEquals("1 hour", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 12, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 12, 0, 0); assertEquals("2 hours", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 13, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 13, 0, 0); assertEquals("3 hours", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 2, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 2, 10, 0, 0); assertEquals("1 day", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 3, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 3, 10, 0, 0); assertEquals("2 days", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 4, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 4, 10, 0, 0); assertEquals("3 days", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 2, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.MARCH, 1, 10, 0, 0); assertEquals("1 month", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 3, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.APRIL, 1, 10, 0, 0); assertEquals("2 months", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 4, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.MAY, 1, 10, 0, 0); assertEquals("3 months", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2011, 1, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2011, Calendar.FEBRUARY, 1, 10, 0, 0); assertEquals("1 year", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2012, 1, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2012, Calendar.FEBRUARY, 1, 10, 0, 0); assertEquals("2 years", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2013, 1, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2013, Calendar.FEBRUARY, 1, 10, 0, 0); assertEquals("3 years", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2011, 4, 5, 23, 38, 12); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2011, Calendar.MAY, 5, 23, 38, 12); assertEquals("1 year 3 months 4 days", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 9, 17, 23, 45, 45); - b = new GregorianCalendar(2015, 3, 7, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.OCTOBER, 17, 23, 45, 45); + b = new GregorianCalendar(2015, Calendar.APRIL, 7, 10, 0, 0); assertEquals("4 years 5 months 20 days", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2011, 4, 31, 10, 0, 0); - b = new GregorianCalendar(2011, 4, 31, 10, 5, 0); + a = new GregorianCalendar(2011, Calendar.MAY, 31, 10, 0, 0); + b = new GregorianCalendar(2011, Calendar.MAY, 31, 10, 5, 0); assertEquals("5 minutes", DateUtil.formatDateDiff(a, b)); } public void testFDDpast() { Calendar a, b; - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 9, 59, 59); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 9, 59, 59); assertEquals("1 second", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 9, 59, 58); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 9, 59, 58); assertEquals("2 seconds", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 9, 59, 57); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 9, 59, 57); assertEquals("3 seconds", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 9, 59, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 9, 59, 0); assertEquals("1 minute", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 9, 58, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 9, 58, 0); assertEquals("2 minutes", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 9, 57, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 9, 57, 0); assertEquals("3 minutes", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 9, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 9, 0, 0); assertEquals("1 hour", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 8, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 8, 0, 0); assertEquals("2 hours", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 1, 7, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 7, 0, 0); assertEquals("3 hours", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 5, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 4, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 5, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 4, 10, 0, 0); assertEquals("1 day", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 5, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 3, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 5, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 3, 10, 0, 0); assertEquals("2 days", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 5, 10, 0, 0); - b = new GregorianCalendar(2010, 1, 2, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 5, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.FEBRUARY, 2, 10, 0, 0); assertEquals("3 days", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 5, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 4, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.JUNE, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.MAY, 1, 10, 0, 0); assertEquals("1 month", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 5, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 3, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.JUNE, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.APRIL, 1, 10, 0, 0); assertEquals("2 months", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 5, 1, 10, 0, 0); - b = new GregorianCalendar(2010, 2, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.JUNE, 1, 10, 0, 0); + b = new GregorianCalendar(2010, Calendar.MARCH, 1, 10, 0, 0); assertEquals("3 months", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2009, 1, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2009, Calendar.FEBRUARY, 1, 10, 0, 0); assertEquals("1 year", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2008, 1, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2008, Calendar.FEBRUARY, 1, 10, 0, 0); assertEquals("2 years", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2007, 1, 1, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2007, Calendar.FEBRUARY, 1, 10, 0, 0); assertEquals("3 years", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 1, 1, 10, 0, 0); - b = new GregorianCalendar(2009, 4, 5, 23, 38, 12); + a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); + b = new GregorianCalendar(2009, Calendar.MAY, 5, 23, 38, 12); assertEquals("8 months 26 days 10 hours", DateUtil.formatDateDiff(a, b)); - a = new GregorianCalendar(2010, 9, 17, 23, 45, 45); - b = new GregorianCalendar(2000, 3, 7, 10, 0, 0); + a = new GregorianCalendar(2010, Calendar.OCTOBER, 17, 23, 45, 45); + b = new GregorianCalendar(2000, Calendar.APRIL, 7, 10, 0, 0); assertEquals("10 years 6 months 10 days", DateUtil.formatDateDiff(a, b)); }