2011-03-19 22:39:51 +00:00
|
|
|
package com.earth2me.essentials;
|
|
|
|
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
import java.io.IOException;
|
2013-05-05 03:13:17 +00:00
|
|
|
import java.math.BigDecimal;
|
2014-02-02 16:07:32 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
2011-03-19 22:39:51 +00:00
|
|
|
import junit.framework.TestCase;
|
2014-02-02 16:07:32 +00:00
|
|
|
import net.ess3.api.MaxMoneyException;
|
2011-05-13 19:18:22 +00:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World.Environment;
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
import org.bukkit.plugin.InvalidDescriptionException;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class UserTest extends TestCase
|
|
|
|
{
|
2011-06-01 10:40:12 +00:00
|
|
|
private final OfflinePlayer base1;
|
|
|
|
private final Essentials ess;
|
|
|
|
private final FakeServer server;
|
2011-03-19 22:39:51 +00:00
|
|
|
|
|
|
|
public UserTest(String testName)
|
|
|
|
{
|
|
|
|
super(testName);
|
2011-05-13 19:18:22 +00:00
|
|
|
server = new FakeServer();
|
|
|
|
server.createWorld("testWorld", Environment.NORMAL);
|
2014-01-20 10:20:13 +00:00
|
|
|
ess = new Essentials(server);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
try
|
|
|
|
{
|
2011-05-13 19:18:22 +00:00
|
|
|
ess.setupForTesting(server);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
}
|
|
|
|
catch (InvalidDescriptionException ex)
|
|
|
|
{
|
|
|
|
fail("InvalidDescriptionException");
|
|
|
|
}
|
|
|
|
catch (IOException ex)
|
|
|
|
{
|
|
|
|
fail("IOException");
|
|
|
|
}
|
2011-07-15 23:33:22 +00:00
|
|
|
base1 = server.createPlayer("testPlayer1", ess);
|
2011-05-13 19:18:22 +00:00
|
|
|
server.addPlayer(base1);
|
2011-08-08 12:40:30 +00:00
|
|
|
ess.getUser(base1);
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void should(String what)
|
|
|
|
{
|
|
|
|
System.out.println(getName() + " should " + what);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testUpdate()
|
|
|
|
{
|
2011-07-15 23:33:22 +00:00
|
|
|
OfflinePlayer base1alt = server.createPlayer(base1.getName(), ess);
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
assertEquals(base1alt, ess.getUser(base1alt).getBase());
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
2011-08-24 04:18:35 +00:00
|
|
|
|
2011-05-13 19:18:22 +00:00
|
|
|
public void testHome()
|
2011-03-19 22:39:51 +00:00
|
|
|
{
|
2011-05-13 19:18:22 +00:00
|
|
|
User user = ess.getUser(base1);
|
|
|
|
Location loc = base1.getLocation();
|
2012-09-15 18:55:12 +00:00
|
|
|
user.setHome("home", loc);
|
2011-07-15 23:33:22 +00:00
|
|
|
OfflinePlayer base2 = server.createPlayer(base1.getName(), ess);
|
2011-05-13 19:18:22 +00:00
|
|
|
User user2 = ess.getUser(base2);
|
2011-08-24 04:18:35 +00:00
|
|
|
|
2011-11-26 21:30:40 +00:00
|
|
|
Location home = user2.getHome(loc);
|
|
|
|
assertNotNull(home);
|
|
|
|
assertEquals(loc.getWorld().getName(), home.getWorld().getName());
|
|
|
|
assertEquals(loc.getX(), home.getX());
|
|
|
|
assertEquals(loc.getY(), home.getY());
|
|
|
|
assertEquals(loc.getZ(), home.getZ());
|
|
|
|
assertEquals(loc.getYaw(), home.getYaw());
|
|
|
|
assertEquals(loc.getPitch(), home.getPitch());
|
2011-05-13 19:18:22 +00:00
|
|
|
}
|
|
|
|
|
2011-03-19 22:39:51 +00:00
|
|
|
public void testMoney()
|
|
|
|
{
|
|
|
|
should("properly set, take, give, and get money");
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
User user = ess.getUser(base1);
|
2013-05-05 09:41:19 +00:00
|
|
|
BigDecimal i = new BigDecimal("100.5");
|
2014-02-02 16:07:32 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
user.setMoney(i);
|
|
|
|
user.takeMoney(new BigDecimal(50));
|
|
|
|
i = i.subtract(BigDecimal.valueOf(50));
|
|
|
|
user.giveMoney(new BigDecimal(25));
|
|
|
|
i = i.add(BigDecimal.valueOf(25));
|
|
|
|
}
|
|
|
|
catch (MaxMoneyException ex)
|
|
|
|
{
|
|
|
|
fail();
|
|
|
|
}
|
|
|
|
|
2013-05-05 09:41:19 +00:00
|
|
|
assertEquals(user.getMoney(), i);
|
2011-03-19 22:39:51 +00:00
|
|
|
}
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
|
2011-03-19 22:39:51 +00:00
|
|
|
public void testGetGroup()
|
|
|
|
{
|
|
|
|
should("return the default group");
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
User user = ess.getUser(base1);
|
2011-03-19 22:39:51 +00:00
|
|
|
assertEquals(user.getGroup(), "default");
|
|
|
|
}
|
|
|
|
}
|