Remove outdated permission plugin handlers, minor test fixes

This commit is contained in:
DoNotSpamPls 2019-01-09 11:07:04 +02:00
parent 1ba6c2a596
commit 21f7b0d468
16 changed files with 171 additions and 256 deletions

View File

@ -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;

View File

@ -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<Class<? extends SuperpermsHandler>> 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");
}
}

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -5,10 +5,10 @@ import org.bukkit.plugin.Plugin;
/**
* Interface to be implemented by a payment method.
* Copyright (C) 2011
* AOL license <http://aol.nexua.org>
*
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun)
* @copyright Copyright (C) 2011
* @license AOL license <http://aol.nexua.org>
*/
public interface Method {
/**

View File

@ -22,7 +22,7 @@ import java.util.Set;
* preferred: "iConomy"
* </pre></blockquote>
*
* @author: Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright: Copyright (C) 2011 @license: AOL license
* @author Nijikokun <nijikokun@shortmail.com> (@nijikokun) @copyright: Copyright (C) 2011 @license: AOL license
* <http://aol.nexua.org>
*/
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<Method> Methods = new HashSet<Method>();
private static final Set<String> Dependencies = new HashSet<String>();
private static final Set<Method> Attachables = new HashSet<Method>();
private static final Set<Method> Methods = new HashSet<>();
private static final Set<String> Dependencies = new HashSet<>();
private static final Set<Method> Attachables = new HashSet<>();
static {
_init();
@ -79,7 +79,7 @@ public class Methods {
*
* @return <code>Set<String></code> - Array of payment methods that are loaded.
*
* @see #setMethod(org.bukkit.plugin.Plugin)
* @see #setMethod(PluginManager)
*/
public static Set<String> getDependencies() {
return Dependencies;
@ -114,8 +114,8 @@ public class Methods {
*
* @return <code>boolean</code>
*
* @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 <code>PluginManager</code> the plugin manager for the server
* @param manager the plugin manager for the server
*
* @return <code>boolean</code> 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()) {

View File

@ -109,9 +109,7 @@ public class VaultEco implements Method {
try {
RegisteredServiceProvider<Economy> 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;
}

View File

@ -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());
}
}
}

View File

@ -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<Player> players = new ArrayList<Player>();
private final List<World> worlds = new ArrayList<World>();
PluginManager pluginManager = new FakePluginManager();
private List<Player> players = new ArrayList<>();
private final List<World> 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<Player> matchPlayer(String string) {
List<Player> matches = new ArrayList<Player>();
List<Player> 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<org.bukkit.OfflinePlayer> 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<RegisteredListener> listeners = new ArrayList<RegisteredListener>();
ArrayList<RegisteredListener> listeners = new ArrayList<>();
@Override
public void registerInterface(Class<? extends PluginLoader> 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.");
}

View File

@ -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

View File

@ -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");
}
}

View File

@ -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) {}
}

View File

@ -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<String> testSet = new HashSet<String>();
Set<String> 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));
}