mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-07-31 18:01:42 +00:00
Unit Tests for Economy API
Finally fixed the Currency format git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1436 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
6c42f42005
commit
fa0a0b3301
9 changed files with 703 additions and 34 deletions
124
Essentials/test/com/earth2me/essentials/EconomyTest.java
Normal file
124
Essentials/test/com/earth2me/essentials/EconomyTest.java
Normal file
|
@ -0,0 +1,124 @@
|
|||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.api.Economy;
|
||||
import com.earth2me.essentials.api.NoLoanPermittedException;
|
||||
import com.earth2me.essentials.api.UserDoesNotExistException;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import junit.framework.TestCase;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
|
||||
|
||||
public class EconomyTest extends TestCase
|
||||
{
|
||||
private OfflinePlayer base1;
|
||||
private Essentials ess;
|
||||
|
||||
public EconomyTest(String testName)
|
||||
{
|
||||
super(testName);
|
||||
ess = new Essentials();
|
||||
FakeServer server = new FakeServer();
|
||||
try
|
||||
{
|
||||
ess.setupForTesting(server);
|
||||
}
|
||||
catch (InvalidDescriptionException ex)
|
||||
{
|
||||
fail("InvalidDescriptionException");
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
fail("IOException");
|
||||
}
|
||||
base1 = new OfflinePlayer("TestPlayer1");
|
||||
server.addPlayer(base1);
|
||||
}
|
||||
|
||||
// only one big test, since we use static instances
|
||||
public void testEconomy()
|
||||
{
|
||||
// test NPC
|
||||
String npcName = "npc1";
|
||||
assertFalse(Economy.playerExists(npcName));
|
||||
assertTrue(Economy.createNPC(npcName));
|
||||
assertTrue(Economy.playerExists(npcName));
|
||||
assertNotNull(ess.getOfflineUser(npcName));
|
||||
try
|
||||
{
|
||||
Economy.removeNPC(npcName);
|
||||
}
|
||||
catch (UserDoesNotExistException ex)
|
||||
{
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
assertFalse(Economy.playerExists(npcName));
|
||||
|
||||
//test Math
|
||||
try
|
||||
{
|
||||
String playerName = "TestPlayer1";
|
||||
assertTrue(Economy.playerExists(playerName));
|
||||
Economy.resetBalance(playerName);
|
||||
assertEquals(0.0, Economy.getMoney(playerName));
|
||||
Economy.add(playerName, 10.0);
|
||||
assertEquals(10.0, Economy.getMoney(playerName));
|
||||
Economy.subtract(playerName, 5.0);
|
||||
assertEquals(5.0, Economy.getMoney(playerName));
|
||||
Economy.multiply(playerName, 2.0);
|
||||
assertEquals(10.0, Economy.getMoney(playerName));
|
||||
Economy.divide(playerName, 2.0);
|
||||
assertEquals(5.0, Economy.getMoney(playerName));
|
||||
Economy.setMoney(playerName, 10.0);
|
||||
assertEquals(10.0, Economy.getMoney(playerName));
|
||||
}
|
||||
catch (NoLoanPermittedException ex)
|
||||
{
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
catch (UserDoesNotExistException ex)
|
||||
{
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
|
||||
//test Format
|
||||
assertEquals("$10", Economy.format(10.0));
|
||||
assertEquals("$10.10", Economy.format(10.10));
|
||||
assertEquals("$10.10", Economy.format(10.102));
|
||||
assertEquals("$10.11", Economy.format(10.109));
|
||||
|
||||
|
||||
//test Exceptions
|
||||
try
|
||||
{
|
||||
String playerName = "TestPlayer1";
|
||||
assertTrue(Economy.playerExists(playerName));
|
||||
Economy.resetBalance(playerName);
|
||||
assertEquals(0.0, Economy.getMoney(playerName));
|
||||
Economy.subtract(playerName, 5.0);
|
||||
fail();
|
||||
}
|
||||
catch (NoLoanPermittedException ex)
|
||||
{
|
||||
}
|
||||
catch (UserDoesNotExistException ex)
|
||||
{
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String playerName = "UnknownPlayer";
|
||||
Economy.resetBalance(playerName);
|
||||
fail();
|
||||
}
|
||||
catch (NoLoanPermittedException ex)
|
||||
{
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
catch (UserDoesNotExistException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue