From 756321d280789ea96ece73dee816eb5c202a46af Mon Sep 17 00:00:00 2001 From: KHobbits Date: Tue, 15 Apr 2014 00:08:02 +0100 Subject: Add UUID mocking support, and fix tests. --- .../test/com/earth2me/essentials/EconomyTest.java | 6 ++-- .../test/com/earth2me/essentials/FakeServer.java | 39 ++++++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/Essentials/test/com/earth2me/essentials/EconomyTest.java b/Essentials/test/com/earth2me/essentials/EconomyTest.java index 34f7f33f8..00d994b2b 100644 --- a/Essentials/test/com/earth2me/essentials/EconomyTest.java +++ b/Essentials/test/com/earth2me/essentials/EconomyTest.java @@ -4,6 +4,8 @@ import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; import java.io.IOException; import junit.framework.TestCase; +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.fail; import net.ess3.api.Economy; import org.bukkit.World.Environment; import org.bukkit.plugin.InvalidDescriptionException; @@ -14,7 +16,7 @@ public class EconomyTest extends TestCase { private final transient Essentials ess; private static final String NPCNAME = "npc1"; - private static final String PLAYERNAME = "TestPlayer1"; + private static final String PLAYERNAME = "testPlayer1"; public EconomyTest(final String testName) { @@ -34,7 +36,7 @@ public class EconomyTest extends TestCase { fail("IOException"); } - server.addPlayer(new OfflinePlayer(PLAYERNAME, ess.getServer())); + server.addPlayer(new OfflinePlayer(PLAYERNAME, ess.getServer())); } // only one big test, since we use static instances diff --git a/Essentials/test/com/earth2me/essentials/FakeServer.java b/Essentials/test/com/earth2me/essentials/FakeServer.java index 2786480c5..55313d60c 100644 --- a/Essentials/test/com/earth2me/essentials/FakeServer.java +++ b/Essentials/test/com/earth2me/essentials/FakeServer.java @@ -698,6 +698,11 @@ public class FakeServer implements Server @Override public org.bukkit.OfflinePlayer getOfflinePlayer(final String string) + { + return createOPlayer(string); + } + + private org.bukkit.OfflinePlayer createOPlayer(final String string) { return new org.bukkit.OfflinePlayer() { @@ -788,6 +793,14 @@ public class FakeServer implements Server @Override public UUID getUniqueId() { + if (string == "testPlayer1") + { + return UUID.fromString("3c9ebe1a-9098-43fd-bc0c-a369b76817ba"); + } + else if (string == "npc1") + { + return null; + } throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; @@ -1170,17 +1183,20 @@ public class FakeServer implements Server } @Override - public CachedServerIcon getServerIcon() { + public CachedServerIcon getServerIcon() + { throw new UnsupportedOperationException("Not supported yet."); } @Override - public CachedServerIcon loadServerIcon(File file) throws IllegalArgumentException, Exception { + public CachedServerIcon loadServerIcon(File file) throws IllegalArgumentException, Exception + { throw new UnsupportedOperationException("Not supported yet."); } @Override - public CachedServerIcon loadServerIcon(BufferedImage bufferedImage) throws IllegalArgumentException, Exception { + public CachedServerIcon loadServerIcon(BufferedImage bufferedImage) throws IllegalArgumentException, Exception + { throw new UnsupportedOperationException("Not supported yet."); } @@ -1211,12 +1227,23 @@ public class FakeServer implements Server @Override public Player getPlayer(UUID arg0) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + for (Player player : players) + { + if (player.getUniqueId().equals(arg0)) + { + return player; + } + } + return null; } @Override - public OfflinePlayer getOfflinePlayer(UUID arg0) + public org.bukkit.OfflinePlayer getOfflinePlayer(UUID arg0) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (arg0.toString().equalsIgnoreCase("3c9ebe1a-9098-43fd-bc0c-a369b76817ba")) + { + return createOPlayer("testPlayer1"); + } + throw new UnsupportedOperationException("Not supported yet."); } } -- cgit v1.2.3