1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package net.ess3;
import net.ess3.api.NoLoanPermittedException;
import net.ess3.api.UserDoesNotExistException;
import org.junit.Test;
public class EconomyTest extends EssentialsTest
{
private final static String NPCNAME = "npc1";
private final static String PLAYERNAME = "TestPlayer1";
public EconomyTest(final String testName)
{
super(testName);
server.addPlayer(PLAYERNAME);
}
// only one big test, since we use static instances
@Test
public void testEconomy()
{
// test NPC
assertFalse("NPC does not exists", ess.getEconomy().playerExists(NPCNAME));
assertTrue("Create NPC", ess.getEconomy().createNPC(NPCNAME));
assertTrue("NPC exists", ess.getEconomy().playerExists(NPCNAME));
assertNull("NPC can not be accessed", ess.getUser(NPCNAME));
try
{
ess.getEconomy().removeNPC(NPCNAME);
}
catch (UserDoesNotExistException ex)
{
fail(ex.getMessage());
}
assertFalse("NPC can be removed",ess.getEconomy().playerExists(NPCNAME));
//test Math
try
{
assertTrue("Player exists", ess.getEconomy().playerExists(PLAYERNAME));
ess.getEconomy().resetBalance(PLAYERNAME);
assertEquals("Player has no money", 0.0, ess.getEconomy().getMoney(PLAYERNAME));
ess.getEconomy().setMoney(PLAYERNAME, 10.0);
assertEquals("Set money", 10.0, ess.getEconomy().getMoney(PLAYERNAME));
}
catch (NoLoanPermittedException ex)
{
fail(ex.getMessage());
}
catch (UserDoesNotExistException ex)
{
fail(ex.getMessage());
}
//test Format
assertEquals("Format $1000", "$1000", ess.getEconomy().format(1000.0));
assertEquals("Format $10", "$10", ess.getEconomy().format(10.0));
assertEquals("Format $10.10", "$10.10", ess.getEconomy().format(10.10));
assertEquals("Format $10.10", "$10.10", ess.getEconomy().format(10.102));
assertEquals("Format $10.11", "$10.11", ess.getEconomy().format(10.109));
//test Exceptions
try
{
assertTrue("Player exists", ess.getEconomy().playerExists(PLAYERNAME));
ess.getEconomy().resetBalance(PLAYERNAME);
assertEquals("Reset balance", 0.0, ess.getEconomy().getMoney(PLAYERNAME));
ess.getEconomy().setMoney(PLAYERNAME, -5.0);
fail("Did not throw exception");
}
catch (NoLoanPermittedException ex)
{
}
catch (UserDoesNotExistException ex)
{
fail(ex.getMessage());
}
try
{
ess.getEconomy().resetBalance("UnknownPlayer");
fail("Did not throw exception");
}
catch (NoLoanPermittedException ex)
{
fail(ex.getMessage());
}
catch (UserDoesNotExistException ex)
{
}
}
}
|