mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-11-22 01:56:22 +01:00
Improvements to tests & version bump to 0.16.1
This commit is contained in:
parent
5663077718
commit
d2fea85ffe
@ -9,7 +9,7 @@
|
||||
<version>0</version>
|
||||
</parent>
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.16.0-SNAPSHOT</version>
|
||||
<version>0.16.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -98,7 +98,7 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
|
||||
Arrays.stream(playersToSync).filter(p -> (p != null) && !p.isOnline()).forEach(p -> {
|
||||
ByteArrayDataOutput bado = ByteStreams.newDataOutput();
|
||||
bado.writeUTF("Forward");
|
||||
bado.writeUTF("ALL");
|
||||
bado.writeUTF("ONLINE");
|
||||
bado.writeUTF("SaneEconomy");
|
||||
bado.writeUTF("SyncPlayer");
|
||||
bado.writeUTF(p.getUniqueId().toString());
|
||||
|
@ -60,6 +60,18 @@ public final class NumberUtils {
|
||||
return filterAmount(currency, parsePositiveDouble(sDouble));
|
||||
}
|
||||
|
||||
public static boolean equals(BigDecimal left, BigDecimal right) {
|
||||
if (left == null) {
|
||||
throw new NullPointerException("left == null");
|
||||
}
|
||||
|
||||
if (right == null) {
|
||||
throw new NullPointerException("right == null");
|
||||
}
|
||||
|
||||
return left.compareTo(right) == 0;
|
||||
}
|
||||
|
||||
private static DecimalFormat constructDecimalFormat() {
|
||||
DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getInstance();
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.appledash.saneeconomy.economy.transaction.TransactionResult;
|
||||
import org.appledash.saneeconomy.test.mock.MockEconomyStorageBackend;
|
||||
import org.appledash.saneeconomy.test.mock.MockOfflinePlayer;
|
||||
import org.appledash.saneeconomy.test.mock.MockSaneEconomy;
|
||||
import org.appledash.saneeconomy.test.util.SaneEcoAssert;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -41,8 +42,8 @@ public class EconomyManagerTest {
|
||||
// Accounts should not exist
|
||||
Assert.assertFalse(this.economyManager.accountExists(playerOne));
|
||||
Assert.assertFalse(this.economyManager.accountExists(playerTwo));
|
||||
Assert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerOne));
|
||||
Assert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerTwo));
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerOne));
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerTwo));
|
||||
|
||||
this.economyManager.setBalance(playerOne, new BigDecimal(100.0));
|
||||
|
||||
@ -51,22 +52,22 @@ public class EconomyManagerTest {
|
||||
Assert.assertFalse(this.economyManager.accountExists(playerTwo));
|
||||
|
||||
// One should have balance, two should not
|
||||
Assert.assertEquals(new BigDecimal("100.00"), this.economyManager.getBalance(playerOne));
|
||||
Assert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerTwo));
|
||||
SaneEcoAssert.assertEquals(new BigDecimal("100.00"), this.economyManager.getBalance(playerOne));
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ZERO, this.economyManager.getBalance(playerTwo));
|
||||
|
||||
// One should be able to transfer to two
|
||||
Assert.assertSame(this.economyManager.transact(new Transaction(this.economyManager.getCurrency(), playerOne, playerTwo, new BigDecimal(50.0), TransactionReason.PLAYER_PAY)).getStatus(), TransactionResult.Status.SUCCESS);
|
||||
|
||||
// One should now have only 50 left, two should have 50 now
|
||||
Assert.assertEquals("Player one should have 50 dollars", new BigDecimal("50.00"), this.economyManager.getBalance(playerOne));
|
||||
Assert.assertEquals("Player two should have 50 dollars", new BigDecimal("50.00"), this.economyManager.getBalance(playerTwo));
|
||||
SaneEcoAssert.assertEquals("Player one should have 50 dollars", new BigDecimal("50.00"), this.economyManager.getBalance(playerOne));
|
||||
SaneEcoAssert.assertEquals("Player two should have 50 dollars", new BigDecimal("50.00"), this.economyManager.getBalance(playerTwo));
|
||||
|
||||
// Ensure that balance addition and subtraction works...
|
||||
Assert.assertEquals(new BigDecimal("25.00"), this.economyManager.transact(
|
||||
SaneEcoAssert.assertEquals(new BigDecimal("25.00"), this.economyManager.transact(
|
||||
new Transaction(this.economyManager.getCurrency(), playerOne, Economable.CONSOLE, new BigDecimal("25.00"), TransactionReason.TEST_TAKE)
|
||||
).getFromBalance());
|
||||
|
||||
Assert.assertEquals(new BigDecimal("50.00"), this.economyManager.transact(
|
||||
SaneEcoAssert.assertEquals(new BigDecimal("50.00"), this.economyManager.transact(
|
||||
new Transaction(this.economyManager.getCurrency(), Economable.CONSOLE, playerOne, new BigDecimal("25.00"), TransactionReason.TEST_GIVE)
|
||||
).getToBalance());
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.appledash.saneeconomy.test;
|
||||
|
||||
import org.appledash.saneeconomy.economy.Currency;
|
||||
import org.appledash.saneeconomy.test.util.SaneEcoAssert;
|
||||
import org.appledash.saneeconomy.utils.NumberUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -17,12 +18,12 @@ public class NumberUtilsTest {
|
||||
@Test
|
||||
public void testParsePositive() {
|
||||
// Valid input
|
||||
Assert.assertEquals(new BigDecimal("69.0"), NumberUtils.parsePositiveDouble("69.0"));
|
||||
SaneEcoAssert.assertEquals(new BigDecimal("69.0"), NumberUtils.parsePositiveDouble("69.0"));
|
||||
// Valid but not positive
|
||||
Assert.assertEquals(BigDecimal.ONE.negate(), NumberUtils.parsePositiveDouble("-10.0"));
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ONE.negate(), NumberUtils.parsePositiveDouble("-10.0"));
|
||||
// Invalid
|
||||
Assert.assertEquals(BigDecimal.ONE.negate(), NumberUtils.parsePositiveDouble("nan"));
|
||||
Assert.assertEquals(BigDecimal.ONE.negate(), NumberUtils.parsePositiveDouble("ponies"));
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ONE.negate(), NumberUtils.parsePositiveDouble("nan"));
|
||||
SaneEcoAssert.assertEquals(BigDecimal.ONE.negate(), NumberUtils.parsePositiveDouble("ponies"));
|
||||
// Infinite
|
||||
// TODO: Not needed with BigDecimal? Assert.assertEquals(BigDecimal.ONE.negate(), NumberUtils.parsePositiveDouble("1E1000000000"));
|
||||
}
|
||||
@ -31,7 +32,7 @@ public class NumberUtilsTest {
|
||||
public void testFilter() {
|
||||
Currency currency = new Currency(null, null, new DecimalFormat("0.00"));
|
||||
|
||||
Assert.assertEquals(new BigDecimal("1337.42"), NumberUtils.filterAmount(currency, new BigDecimal("1337.420")));
|
||||
SaneEcoAssert.assertEquals(new BigDecimal("1337.42"), NumberUtils.filterAmount(currency, new BigDecimal("1337.420")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -47,4 +48,14 @@ public class NumberUtilsTest {
|
||||
Locale.setDefault(old);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigDecimalEquals() {
|
||||
BigDecimal one = new BigDecimal("100.0");
|
||||
BigDecimal two = new BigDecimal("100.00");
|
||||
BigDecimal three = new BigDecimal("100.1");
|
||||
|
||||
Assert.assertTrue("100.0 should equal 100.00", NumberUtils.equals(one, two));
|
||||
Assert.assertFalse("100.0 should not equal 100.1", NumberUtils.equals(one, three));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package org.appledash.saneeconomy.test.util;
|
||||
|
||||
import org.appledash.saneeconomy.utils.NumberUtils;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public final class SaneEcoAssert {
|
||||
private SaneEcoAssert() {
|
||||
}
|
||||
|
||||
public static void assertEquals(BigDecimal left, BigDecimal right) {
|
||||
Assert.assertTrue(String.format("%s != %s", left.toPlainString(), right.toPlainString()), NumberUtils.equals(left, right));
|
||||
}
|
||||
|
||||
public static void assertEquals(String message, BigDecimal left, BigDecimal right) {
|
||||
Assert.assertTrue(message, NumberUtils.equals(left, right));
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>org.appledash</groupId>
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.14.0-SNAPSHOT</version>
|
||||
<version>0.16.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>org.appledash</groupId>
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.14.0-SNAPSHOT</version>
|
||||
<version>0.16.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>org.appledash</groupId>
|
||||
<artifactId>SaneEconomyCore</artifactId>
|
||||
<version>0.14.0-SNAPSHOT</version>
|
||||
<version>0.16.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user