killbill-aplcache
Changes
beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java 40(+20 -20)
beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationInvoiceWithRepairLogic.java 36(+18 -18)
invoice/src/test/java/com/ning/billing/invoice/api/invoice/TestDefaultInvoicePaymentApi.java 4(+2 -2)
invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java 43(+20 -23)
invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorRepairUnit.java 4(+2 -2)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java 40(+21 -19)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java 21(+11 -10)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java 9(+5 -4)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java 13(+7 -6)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java 27(+14 -13)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java 21(+11 -10)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java 44(+28 -16)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java 15(+9 -6)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java 36(+14 -22)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java 21(+11 -10)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java 47(+24 -23)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java 9(+5 -4)
invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java 8(+0 -8)
util/pom.xml 5(+5 -0)
Details
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
index cccafc3..3d4c8a2 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueIntegration.java
@@ -171,7 +171,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 3,
callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 30), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("249.95")),
// Repair for the part that was blocked
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-166.64")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-166.63")));
// 2012, 7, 17 => Retry P1
addDaysAndCheckForCompletion(7, NextEvent.PAYMENT_ERROR);
@@ -189,7 +189,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 4, callContext,
// New invoice for the part that was unblocked
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("64.51")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("64.50")));
// Add 10 days to generate next invoice. We verify that we indeed have a notification for nextBillingDate
addDaysAndCheckForCompletion(10, NextEvent.INVOICE, NextEvent.PAYMENT);
@@ -260,7 +260,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 3,
callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 30), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("249.95")),
// Repair for the part that was blocked
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-166.64")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-166.63")));
// 2012, 7, 17 => Retry P1
addDaysAndCheckForCompletion(7, NextEvent.PAYMENT_ERROR);
@@ -356,7 +356,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 3,
callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 30), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("249.95")),
// Repair for the part that was blocked
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-166.64")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-166.63")));
// 2012, 7, 17 => Retry P1
addDaysAndCheckForCompletion(7, NextEvent.PAYMENT_ERROR);
@@ -386,7 +386,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 4, callContext,
// New invoice for the partial period since we unblocked on the 1st and so are missing the 31 july
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 8, 1), new LocalDate(2012, 8, 31), InvoiceItemType.RECURRING, new BigDecimal("241.88")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 8, 1), new LocalDate(2012, 8, 31), InvoiceItemType.RECURRING, new BigDecimal("241.89")));
// Move one month ahead, and check if we get the next invoice
addDaysAndCheckForCompletion(30, NextEvent.INVOICE, NextEvent.PAYMENT);
@@ -453,7 +453,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 3,
callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 30), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("249.95")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-166.64")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-166.63")));
// 2012, 7, 17 => Retry P1
addDaysAndCheckForCompletion(7, NextEvent.PAYMENT_ERROR);
@@ -471,24 +471,24 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 4, callContext,
// Item for the upgraded recurring plan
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("64.51")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("64.50")));
// Do an upgrade now
checkChangePlanWithOverdueState(baseEntitlement, false, true);
invoiceChecker.checkRepairedInvoice(account.getId(), 4, callContext,
// Item for the upgraded recurring plan
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("64.51")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("64.50")),
// Repair for upgrade
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-64.51")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-64.50")),
// CBA generated
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 23), InvoiceItemType.CBA_ADJ, new BigDecimal("64.51")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 23), InvoiceItemType.CBA_ADJ, new BigDecimal("64.50")));
invoiceChecker.checkInvoice(account.getId(), 5, callContext,
// Item for the upgraded recurring plan
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("154.85")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("154.83")),
// Repair for upgrade
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 23), InvoiceItemType.CBA_ADJ, new BigDecimal("-64.51")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 23), InvoiceItemType.CBA_ADJ, new BigDecimal("-64.50")));
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 7, 31), callContext);
@@ -536,7 +536,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 2,
callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 31), new LocalDate(2013, 5, 31), InvoiceItemType.RECURRING, new BigDecimal("2399.95")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2013, 5, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-2136.92")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 10), new LocalDate(2013, 5, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-2136.94")));
// 2012, 7, 18 => Retry P0
addDaysAndCheckForCompletion(8, NextEvent.PAYMENT_ERROR);
@@ -550,7 +550,7 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 3, callContext,
// New invoice for the part that was unblocked up to the BCD
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("52.56")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 23), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("52.46")));
// Move to 2012, 7, 31 and Make a change of plan
addDaysAndCheckForCompletion(8, NextEvent.INVOICE, NextEvent.PAYMENT);
@@ -651,20 +651,20 @@ public class TestOverdueIntegration extends TestOverdueBase {
invoiceChecker.checkInvoice(account.getId(), 4, callContext,
// Item for the upgraded recurring plan
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("48.37")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("48.38")));
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 7, 31), callContext);
checkChangePlanWithOverdueState(baseEntitlement, false, true);
invoiceChecker.checkRepairedInvoice(account.getId(), 4, callContext,
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("48.37")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-48.37")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 25), InvoiceItemType.CBA_ADJ, new BigDecimal("48.37")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("48.38")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 31), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-48.38")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 25), InvoiceItemType.CBA_ADJ, new BigDecimal("48.38")));
invoiceChecker.checkInvoice(account.getId(), 5, callContext,
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("116.09")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 25), InvoiceItemType.CBA_ADJ, new BigDecimal("-48.37")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 31), InvoiceItemType.RECURRING, new BigDecimal("116.12")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 7, 25), new LocalDate(2012, 7, 25), InvoiceItemType.CBA_ADJ, new BigDecimal("-48.38")));
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 7, 31), callContext);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBundleTransfer.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBundleTransfer.java
index 6a15797..7cd60e9 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBundleTransfer.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBundleTransfer.java
@@ -207,7 +207,7 @@ public class TestBundleTransfer extends TestIntegrationBase {
// CHECK OLD ACCOUNTS ITEMS
ImmutableList<ExpectedInvoiceItemCheck> toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 9), InvoiceItemType.RECURRING, new BigDecimal("66.66")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 9), InvoiceItemType.RECURRING, new BigDecimal("66.65")),
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 3), new LocalDate(2012, 5, 9), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-49.99")),
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 3), new LocalDate(2012, 5, 3), InvoiceItemType.CBA_ADJ, new BigDecimal("49.99")));
invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
index 9d1ce91..dcb5bc2 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
@@ -127,7 +127,7 @@ public class TestIntegration extends TestIntegrationBase {
setDateAndCheckForCompletion(new DateTime(2012, 3, 1, 23, 59, 59, 0, testTimeZone));
setDateAndCheckForCompletion(new DateTime(2012, 3, 2, 23, 59, 59, 0, testTimeZone), NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT);
invoiceChecker.checkInvoice(account.getId(), invoiceItemCount++, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2),
- new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("561.25")));
+ new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("561.24")));
invoiceChecker.checkChargedThroughDate(subscription.getId(), new LocalDate(2012, 3, 31), callContext);
//
@@ -291,7 +291,7 @@ public class TestIntegration extends TestIntegrationBase {
setDateAndCheckForCompletion(new DateTime(2012, 3, 2, 23, 59, 59, 0, testTimeZone), NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT);
// PRO_RATION
invoiceChecker.checkInvoice(account.getId(), invoiceItemCount++, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2),
- new LocalDate(2012, 3, 3), InvoiceItemType.RECURRING, new BigDecimal("20.70")));
+ new LocalDate(2012, 3, 3), InvoiceItemType.RECURRING, new BigDecimal("20.69")));
invoiceChecker.checkChargedThroughDate(subscription.getId(), new LocalDate(2012, 3, 3), callContext);
setDateAndCheckForCompletion(new DateTime(2012, 3, 3, 23, 59, 59, 0, testTimeZone), NextEvent.INVOICE, NextEvent.PAYMENT);
@@ -527,8 +527,8 @@ public class TestIntegration extends TestIntegrationBase {
invoiceChecker.checkInvoice(account.getId(), 2, callContext,
new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2), new LocalDate(2012, 4, 2), InvoiceItemType.RECURRING, new BigDecimal("249.95")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 4), new LocalDate(2012, 4, 2), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-233.83")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 4), new LocalDate(2012, 3, 4), InvoiceItemType.CBA_ADJ, new BigDecimal("233.83")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 4), new LocalDate(2012, 4, 2), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-233.82")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 4), new LocalDate(2012, 3, 4), InvoiceItemType.CBA_ADJ, new BigDecimal("233.82")));
entitlement = (DefaultEntitlement) entitlementApi.getEntitlementForId(baseEntitlement.getId(), callContext);
Assert.assertEquals(entitlement.getState(), EntitlementState.BLOCKED);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationInvoiceWithRepairLogic.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationInvoiceWithRepairLogic.java
index 2332a52..0358452 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationInvoiceWithRepairLogic.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationInvoiceWithRepairLogic.java
@@ -148,8 +148,8 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
// TODO PIERRE The cba start_date/end_date are created using the callcontext
new ExpectedInvoiceItemCheck(callContext.getCreatedDate().toLocalDate(), callContext.getCreatedDate().toLocalDate(), InvoiceItemType.CBA_ADJ, new BigDecimal("10")),
// You can check here that 239.95 - 249.95/31 = 231.88
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 2), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-231.88")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 2), new LocalDate(2012, 5, 2), InvoiceItemType.CBA_ADJ, new BigDecimal("231.88")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 2), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-231.89")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 2), new LocalDate(2012, 5, 2), InvoiceItemType.CBA_ADJ, new BigDecimal("231.89")));
invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
@@ -246,8 +246,8 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("599.95")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-483.86")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 5, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("483.86")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-483.83")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 5, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("483.83")));
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
@@ -275,8 +275,8 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("599.95")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-483.86")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 5, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("483.86")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-483.83")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 5, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("483.83")));
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
@@ -312,8 +312,8 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("599.95")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-483.86")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 5, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("483.86")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-483.83")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 5, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("483.83")));
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
@@ -354,8 +354,8 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("599.95")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-483.86")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 5, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("483.86")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 6, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-483.83")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 7), new LocalDate(2012, 5, 7), InvoiceItemType.CBA_ADJ, new BigDecimal("483.83")));
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
@@ -543,9 +543,9 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 11), InvoiceItemType.RECURRING, new BigDecimal("65.76")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 11), InvoiceItemType.RECURRING, new BigDecimal("65.75")),
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("169.32")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-235.08")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-235.07")));
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
// NOW SWITCH BACK TO PARTIAL REPAIR LOGIC AND GENERATE NEXT 2 INVOICES
@@ -566,9 +566,9 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 11), InvoiceItemType.RECURRING, new BigDecimal("65.76")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 11), InvoiceItemType.RECURRING, new BigDecimal("65.75")),
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("169.32")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-235.08")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-235.07")));
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
// AND THEN CHECK NEW INVOICE
@@ -665,9 +665,9 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 11), InvoiceItemType.RECURRING, new BigDecimal("65.76")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 11), InvoiceItemType.RECURRING, new BigDecimal("65.75")),
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("169.32")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-235.08")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-235.07")));
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
// NOW SWITCH BACK TO PARTIAL REPAIR LOGIC AND GENERATE NEXT 2 INVOICES
@@ -689,9 +689,9 @@ public class TestIntegrationInvoiceWithRepairLogic extends TestIntegrationBase {
invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 11), InvoiceItemType.RECURRING, new BigDecimal("65.76")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2012, 5, 11), InvoiceItemType.RECURRING, new BigDecimal("65.75")),
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("169.32")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-235.08")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-235.07")));
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
// AND THEN CHECK NEW INVOICE
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPaymentRefund.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPaymentRefund.java
index c33eca2..e744b9b 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPaymentRefund.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPaymentRefund.java
@@ -71,27 +71,27 @@ public class TestPaymentRefund extends TestIntegrationBase {
public void testRefundWithNoAdjustments() throws Exception {
// Although we don't adjust the invoice, the invoicing system sends an event because invoice balance changes and overdue system-- in particular-- needs to know about it.
refundPaymentAndCheckForCompletion(account, payment, NextEvent.INVOICE_ADJUSTMENT);
- refundChecker.checkRefund(payment.getId(), callContext, new ExpectedRefundCheck(payment.getId(), false, new BigDecimal("233.83"), Currency.USD, initialCreationDate.toLocalDate()));
+ refundChecker.checkRefund(payment.getId(), callContext, new ExpectedRefundCheck(payment.getId(), false, new BigDecimal("233.82"), Currency.USD, initialCreationDate.toLocalDate()));
}
@Test(groups = "slow")
public void testRefundWithInvoiceItemAdjustemts() throws Exception {
refundPaymentWithInvoiceItemAdjAndCheckForCompletion(account, payment, invoiceItems, NextEvent.INVOICE_ADJUSTMENT);
- refundChecker.checkRefund(payment.getId(), callContext, new ExpectedRefundCheck(payment.getId(), true, new BigDecimal("233.83"), Currency.USD, initialCreationDate.toLocalDate()));
+ refundChecker.checkRefund(payment.getId(), callContext, new ExpectedRefundCheck(payment.getId(), true, new BigDecimal("233.82"), Currency.USD, initialCreationDate.toLocalDate()));
invoice = invoiceChecker.checkInvoice(account.getId(), invoiceItemCount++, callContext,
new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2),
- new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("233.83")),
- new ExpectedInvoiceItemCheck(InvoiceItemType.ITEM_ADJ, new BigDecimal("-233.83")));
+ new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("233.82")),
+ new ExpectedInvoiceItemCheck(InvoiceItemType.ITEM_ADJ, new BigDecimal("-233.82")));
}
@Test(groups = "slow")
public void testRefundWithInvoiceAdjustment() throws Exception {
refundPaymentWithAdjustmenttAndCheckForCompletion(account, payment, NextEvent.INVOICE_ADJUSTMENT);
- refundChecker.checkRefund(payment.getId(), callContext, new ExpectedRefundCheck(payment.getId(), true, new BigDecimal("233.83"), Currency.USD, initialCreationDate.toLocalDate()));
+ refundChecker.checkRefund(payment.getId(), callContext, new ExpectedRefundCheck(payment.getId(), true, new BigDecimal("233.82"), Currency.USD, initialCreationDate.toLocalDate()));
invoice = invoiceChecker.checkInvoice(account.getId(), invoiceItemCount++, callContext,
new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2),
- new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("233.83")),
- new ExpectedInvoiceItemCheck(InvoiceItemType.REFUND_ADJ, new BigDecimal("-233.83")));
+ new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("233.82")),
+ new ExpectedInvoiceItemCheck(InvoiceItemType.REFUND_ADJ, new BigDecimal("-233.82")));
}
@@ -118,8 +118,8 @@ public class TestPaymentRefund extends TestIntegrationBase {
setDateAndCheckForCompletion(new DateTime(2012, 3, 2, 23, 59, 59, 0, testTimeZone), NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT);
invoice = invoiceChecker.checkInvoice(account.getId(), ++invoiceItemCount, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 3, 2),
- new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("233.83")));
- payment = paymentChecker.checkPayment(account.getId(), 1, callContext, new ExpectedPaymentCheck(new LocalDate(2012, 3, 2), new BigDecimal("233.83"), PaymentStatus.SUCCESS, invoice.getId(), Currency.USD));
+ new LocalDate(2012, 3, 31), InvoiceItemType.RECURRING, new BigDecimal("233.82")));
+ payment = paymentChecker.checkPayment(account.getId(), 1, callContext, new ExpectedPaymentCheck(new LocalDate(2012, 3, 2), new BigDecimal("233.82"), PaymentStatus.SUCCESS, invoice.getId(), Currency.USD));
// Filter and extract UUId from all Recuring invoices
invoiceItems = new HashSet<UUID>(Collections2.transform(Collections2.filter(invoice.getInvoiceItems(), new Predicate<InvoiceItem>() {
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestSubscription.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestSubscription.java
index c99bca8..139e004 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestSubscription.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestSubscription.java
@@ -84,8 +84,8 @@ public class TestSubscription extends TestIntegrationBase {
assertEquals(invoices.size(), 3);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2013, 5, 1), InvoiceItemType.RECURRING, new BigDecimal("2399.95")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2013, 5, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-2334.19")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("2334.19")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2013, 5, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-2334.20")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("2334.20")));
invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
@@ -109,10 +109,9 @@ public class TestSubscription extends TestIntegrationBase {
invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("137.76")),
- new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-137.76")));
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("137.70")),
+ new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 11), new LocalDate(2012, 5, 11), InvoiceItemType.CBA_ADJ, new BigDecimal("-137.70")));
invoiceChecker.checkInvoice(invoices.get(3).getId(), callContext, toBeChecked);
}
-
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/calculator/InvoiceCalculatorUtils.java b/invoice/src/main/java/com/ning/billing/invoice/calculator/InvoiceCalculatorUtils.java
index d3007ba..6dca3ab 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/calculator/InvoiceCalculatorUtils.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/calculator/InvoiceCalculatorUtils.java
@@ -22,20 +22,18 @@ import javax.annotation.Nullable;
import org.joda.time.DateTime;
+import com.ning.billing.catalog.api.Currency;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceItemType;
import com.ning.billing.invoice.api.InvoicePayment;
import com.ning.billing.invoice.api.InvoicePaymentType;
-import com.ning.billing.invoice.model.InvoicingConfiguration;
+import com.ning.billing.util.currency.KillBillMoney;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
public abstract class InvoiceCalculatorUtils {
- private static final int NUMBER_OF_DECIMALS = InvoicingConfiguration.getNumberOfDecimals();
- private static final int ROUNDING_METHOD = InvoicingConfiguration.getRoundingMode();
-
// Invoice adjustments
public static boolean isInvoiceAdjustmentItem(final InvoiceItem invoiceItem, final Iterable<InvoiceItem> otherInvoiceItems) {
// Either REFUND_ADJ
@@ -65,24 +63,26 @@ public abstract class InvoiceCalculatorUtils {
InvoiceItemType.RECURRING.equals(invoiceItem.getInvoiceItemType());
}
- public static BigDecimal computeInvoiceBalance(@Nullable final Iterable<InvoiceItem> invoiceItems,
+ public static BigDecimal computeInvoiceBalance(final Currency currency,
+ @Nullable final Iterable<InvoiceItem> invoiceItems,
@Nullable final Iterable<InvoicePayment> invoicePayments) {
- return computeInvoiceAmountCharged(invoiceItems)
- .add(computeInvoiceAmountCredited(invoiceItems))
- .add(computeInvoiceAmountAdjustedForAccountCredit(invoiceItems))
+ final BigDecimal invoiceBalance = computeInvoiceAmountCharged(currency, invoiceItems)
+ .add(computeInvoiceAmountCredited(currency, invoiceItems))
+ .add(computeInvoiceAmountAdjustedForAccountCredit(currency, invoiceItems))
.add(
- computeInvoiceAmountPaid(invoicePayments).negate()
+ computeInvoiceAmountPaid(currency, invoicePayments).negate()
.add(
- computeInvoiceAmountRefunded(invoicePayments).negate()
+ computeInvoiceAmountRefunded(currency, invoicePayments).negate()
)
- )
- .setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ );
+
+ return KillBillMoney.of(invoiceBalance, currency);
}
// Snowflake for the CREDIT_ADJ on its own invoice
- private static BigDecimal computeInvoiceAmountAdjustedForAccountCredit(final Iterable<InvoiceItem> invoiceItems) {
+ private static BigDecimal computeInvoiceAmountAdjustedForAccountCredit(final Currency currency, final Iterable<InvoiceItem> invoiceItems) {
BigDecimal amountAdjusted = BigDecimal.ZERO;
- if (invoiceItems == null) {
+ if (invoiceItems == null || !invoiceItems.iterator().hasNext()) {
return amountAdjusted;
}
@@ -102,12 +102,13 @@ public abstract class InvoiceCalculatorUtils {
amountAdjusted = amountAdjusted.add(invoiceItem.getAmount());
}
}
- return amountAdjusted.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+
+ return KillBillMoney.of(amountAdjusted, currency);
}
- public static BigDecimal computeInvoiceAmountCharged(@Nullable final Iterable<InvoiceItem> invoiceItems) {
+ public static BigDecimal computeInvoiceAmountCharged(final Currency currency, @Nullable final Iterable<InvoiceItem> invoiceItems) {
BigDecimal amountCharged = BigDecimal.ZERO;
- if (invoiceItems == null) {
+ if (invoiceItems == null || !invoiceItems.iterator().hasNext()) {
return amountCharged;
}
@@ -125,12 +126,13 @@ public abstract class InvoiceCalculatorUtils {
amountCharged = amountCharged.add(invoiceItem.getAmount());
}
}
- return amountCharged.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+
+ return KillBillMoney.of(amountCharged, currency);
}
- public static BigDecimal computeInvoiceOriginalAmountCharged(final DateTime invoiceCreatedDate, @Nullable final Iterable<InvoiceItem> invoiceItems) {
+ public static BigDecimal computeInvoiceOriginalAmountCharged(final DateTime invoiceCreatedDate, final Currency currency, @Nullable final Iterable<InvoiceItem> invoiceItems) {
BigDecimal amountCharged = BigDecimal.ZERO;
- if (invoiceItems == null) {
+ if (invoiceItems == null || !invoiceItems.iterator().hasNext()) {
return amountCharged;
}
@@ -140,12 +142,13 @@ public abstract class InvoiceCalculatorUtils {
amountCharged = amountCharged.add(invoiceItem.getAmount());
}
}
- return amountCharged.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+
+ return KillBillMoney.of(amountCharged, currency);
}
- public static BigDecimal computeInvoiceAmountCredited(@Nullable final Iterable<InvoiceItem> invoiceItems) {
+ public static BigDecimal computeInvoiceAmountCredited(final Currency currency, @Nullable final Iterable<InvoiceItem> invoiceItems) {
BigDecimal amountCredited = BigDecimal.ZERO;
- if (invoiceItems == null) {
+ if (invoiceItems == null || !invoiceItems.iterator().hasNext()) {
return amountCredited;
}
@@ -154,12 +157,13 @@ public abstract class InvoiceCalculatorUtils {
amountCredited = amountCredited.add(invoiceItem.getAmount());
}
}
- return amountCredited.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+
+ return KillBillMoney.of(amountCredited, currency);
}
- public static BigDecimal computeInvoiceAmountPaid(@Nullable final Iterable<InvoicePayment> invoicePayments) {
+ public static BigDecimal computeInvoiceAmountPaid(final Currency currency, @Nullable final Iterable<InvoicePayment> invoicePayments) {
BigDecimal amountPaid = BigDecimal.ZERO;
- if (invoicePayments == null) {
+ if (invoicePayments == null || !invoicePayments.iterator().hasNext()) {
return amountPaid;
}
@@ -168,12 +172,13 @@ public abstract class InvoiceCalculatorUtils {
amountPaid = amountPaid.add(invoicePayment.getAmount());
}
}
- return amountPaid.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+
+ return KillBillMoney.of(amountPaid, currency);
}
- public static BigDecimal computeInvoiceAmountRefunded(@Nullable final Iterable<InvoicePayment> invoicePayments) {
+ public static BigDecimal computeInvoiceAmountRefunded(final Currency currency, @Nullable final Iterable<InvoicePayment> invoicePayments) {
BigDecimal amountRefunded = BigDecimal.ZERO;
- if (invoicePayments == null) {
+ if (invoicePayments == null || !invoicePayments.iterator().hasNext()) {
return amountRefunded;
}
@@ -183,6 +188,7 @@ public abstract class InvoiceCalculatorUtils {
amountRefunded = amountRefunded.add(invoicePayment.getAmount());
}
}
- return amountRefunded.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+
+ return KillBillMoney.of(amountRefunded, currency);
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceModelDaoHelper.java b/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceModelDaoHelper.java
index 8dedb42..f53875f 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceModelDaoHelper.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceModelDaoHelper.java
@@ -34,28 +34,29 @@ public class InvoiceModelDaoHelper {
private InvoiceModelDaoHelper() {}
public static BigDecimal getBalance(final InvoiceModelDao invoiceModelDao) {
- return InvoiceCalculatorUtils.computeInvoiceBalance(
- Iterables.transform(invoiceModelDao.getInvoiceItems(), new Function<InvoiceItemModelDao, InvoiceItem>() {
- @Override
- public InvoiceItem apply(final InvoiceItemModelDao input) {
- return InvoiceItemFactory.fromModelDao(input);
- }
- }),
- Iterables.transform(invoiceModelDao.getInvoicePayments(), new Function<InvoicePaymentModelDao, InvoicePayment>() {
- @Nullable
- @Override
- public InvoicePayment apply(final InvoicePaymentModelDao input) {
- return new DefaultInvoicePayment(input);
- }
- }));
+ return InvoiceCalculatorUtils.computeInvoiceBalance(invoiceModelDao.getCurrency(),
+ Iterables.transform(invoiceModelDao.getInvoiceItems(), new Function<InvoiceItemModelDao, InvoiceItem>() {
+ @Override
+ public InvoiceItem apply(final InvoiceItemModelDao input) {
+ return InvoiceItemFactory.fromModelDao(input);
+ }
+ }),
+ Iterables.transform(invoiceModelDao.getInvoicePayments(), new Function<InvoicePaymentModelDao, InvoicePayment>() {
+ @Nullable
+ @Override
+ public InvoicePayment apply(final InvoicePaymentModelDao input) {
+ return new DefaultInvoicePayment(input);
+ }
+ }));
}
public static BigDecimal getCBAAmount(final InvoiceModelDao invoiceModelDao) {
- return InvoiceCalculatorUtils.computeInvoiceAmountCredited(Iterables.transform(invoiceModelDao.getInvoiceItems(), new Function<InvoiceItemModelDao, InvoiceItem>() {
- @Override
- public InvoiceItem apply(final InvoiceItemModelDao input) {
- return InvoiceItemFactory.fromModelDao(input);
- }
- }));
+ return InvoiceCalculatorUtils.computeInvoiceAmountCredited(invoiceModelDao.getCurrency(),
+ Iterables.transform(invoiceModelDao.getInvoiceItems(), new Function<InvoiceItemModelDao, InvoiceItem>() {
+ @Override
+ public InvoiceItem apply(final InvoiceItemModelDao input) {
+ return InvoiceItemFactory.fromModelDao(input);
+ }
+ }));
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/generator/DefaultInvoiceGenerator.java b/invoice/src/main/java/com/ning/billing/invoice/generator/DefaultInvoiceGenerator.java
index 4d82d6d..2d4d2e8 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/generator/DefaultInvoiceGenerator.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/generator/DefaultInvoiceGenerator.java
@@ -46,7 +46,6 @@ import com.ning.billing.invoice.model.DefaultInvoice;
import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.model.InAdvanceBillingMode;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
-import com.ning.billing.invoice.model.InvoicingConfiguration;
import com.ning.billing.invoice.model.RecurringInvoiceItem;
import com.ning.billing.invoice.model.RecurringInvoiceItemData;
import com.ning.billing.invoice.model.RepairAdjInvoiceItem;
@@ -54,6 +53,7 @@ import com.ning.billing.junction.BillingEvent;
import com.ning.billing.junction.BillingEventSet;
import com.ning.billing.junction.BillingModeType;
import com.ning.billing.util.config.InvoiceConfig;
+import com.ning.billing.util.currency.KillBillMoney;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
@@ -92,8 +92,6 @@ import com.google.inject.Inject;
public class DefaultInvoiceGenerator implements InvoiceGenerator {
private static final Logger log = LoggerFactory.getLogger(DefaultInvoiceGenerator.class);
- private static final int ROUNDING_MODE = InvoicingConfiguration.getRoundingMode();
- private static final int NUMBER_OF_DECIMALS = InvoicingConfiguration.getNumberOfDecimals();
private final Clock clock;
private final InvoiceConfig config;
@@ -517,7 +515,7 @@ public class DefaultInvoiceGenerator implements InvoiceGenerator {
final BigDecimal rate = thisEvent.getRecurringPrice();
if (rate != null) {
- final BigDecimal amount = itemDatum.getNumberOfCycles().multiply(rate).setScale(NUMBER_OF_DECIMALS, ROUNDING_MODE);
+ final BigDecimal amount = KillBillMoney.of(itemDatum.getNumberOfCycles().multiply(rate), currency);
final RecurringInvoiceItem recurringItem = new RecurringInvoiceItem(invoiceId,
accountId,
diff --git a/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java b/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java
index ff1591c..62ac263 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/generator/InvoiceDateUtils.java
@@ -18,30 +18,22 @@ package com.ning.billing.invoice.generator;
import java.math.BigDecimal;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
import org.joda.time.Days;
import org.joda.time.LocalDate;
import org.joda.time.Months;
-import org.joda.time.MutableDateTime;
import com.ning.billing.catalog.api.BillingPeriod;
-import com.ning.billing.invoice.model.InvoicingConfiguration;
+import com.ning.billing.util.currency.KillBillMoney;
public class InvoiceDateUtils {
- private static final int ROUNDING_METHOD = InvoicingConfiguration.getRoundingMode();
- private static final int NUMBER_OF_DECIMALS = InvoicingConfiguration.getNumberOfDecimals();
-
-
/**
- *
* Called internally to calculate proration or when we recalculate approximate repair amount
*
- * @param startDate start date of the prorated interval
- * @param endDate end date of the prorated interval
- * @param previousBillingCycleDate start date of the period
- * @param nextBillingCycleDate end date of the period
+ * @param startDate start date of the prorated interval
+ * @param endDate end date of the prorated interval
+ * @param previousBillingCycleDate start date of the period
+ * @param nextBillingCycleDate end date of the period
* @return
*/
public static BigDecimal calculateProrationBetweenDates(final LocalDate startDate, final LocalDate endDate, final LocalDate previousBillingCycleDate, final LocalDate nextBillingCycleDate) {
@@ -57,10 +49,9 @@ public class InvoiceDateUtils {
final BigDecimal daysInPeriod = new BigDecimal(daysBetween);
final BigDecimal days = new BigDecimal(Days.daysBetween(startDate, endDate).getDays());
- return days.divide(daysInPeriod, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ return days.divide(daysInPeriod, KillBillMoney.MAX_SCALE, KillBillMoney.ROUNDING_METHOD);
}
-
public static BigDecimal calculateProRationBeforeFirstBillingPeriod(final LocalDate startDate, final LocalDate nextBillingCycleDate,
final BillingPeriod billingPeriod) {
final LocalDate previousBillingCycleDate = nextBillingCycleDate.plusMonths(-billingPeriod.getNumberOfMonths());
@@ -149,7 +140,6 @@ public class InvoiceDateUtils {
}
}
-
public static BigDecimal calculateProRationAfterLastBillingCycleDate(final LocalDate endDate, final LocalDate previousBillThroughDate,
final BillingPeriod billingPeriod) {
// Note: assumption is that previousBillThroughDate is correctly aligned with the billing cycle day
diff --git a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoice.java b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoice.java
index e75063b..939f3ca 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoice.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoice.java
@@ -28,6 +28,7 @@ import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.entity.EntityBase;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoicePayment;
@@ -35,7 +36,6 @@ import com.ning.billing.invoice.calculator.InvoiceCalculatorUtils;
import com.ning.billing.invoice.dao.InvoiceItemModelDao;
import com.ning.billing.invoice.dao.InvoiceModelDao;
import com.ning.billing.invoice.dao.InvoicePaymentModelDao;
-import com.ning.billing.entity.EntityBase;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
@@ -65,8 +65,8 @@ public class DefaultInvoice extends EntityBase implements Invoice {
// Used to hydrate invoice from persistence layer
public DefaultInvoice(final UUID invoiceId, @Nullable final DateTime createdDate, final UUID accountId,
- @Nullable final Integer invoiceNumber, final LocalDate invoiceDate,
- final LocalDate targetDate, final Currency currency, final Currency processedCurrency, final boolean isMigrationInvoice) {
+ @Nullable final Integer invoiceNumber, final LocalDate invoiceDate,
+ final LocalDate targetDate, final Currency currency, final Currency processedCurrency, final boolean isMigrationInvoice) {
super(invoiceId, createdDate, createdDate);
this.accountId = accountId;
this.invoiceNumber = invoiceNumber;
@@ -187,32 +187,32 @@ public class DefaultInvoice extends EntityBase implements Invoice {
@Override
public BigDecimal getPaidAmount() {
- return InvoiceCalculatorUtils.computeInvoiceAmountPaid(payments);
+ return InvoiceCalculatorUtils.computeInvoiceAmountPaid(currency, payments);
}
@Override
public BigDecimal getOriginalChargedAmount() {
- return InvoiceCalculatorUtils.computeInvoiceOriginalAmountCharged(createdDate, invoiceItems);
+ return InvoiceCalculatorUtils.computeInvoiceOriginalAmountCharged(createdDate, currency, invoiceItems);
}
@Override
public BigDecimal getChargedAmount() {
- return InvoiceCalculatorUtils.computeInvoiceAmountCharged(invoiceItems);
+ return InvoiceCalculatorUtils.computeInvoiceAmountCharged(currency, invoiceItems);
}
@Override
public BigDecimal getCreditedAmount() {
- return InvoiceCalculatorUtils.computeInvoiceAmountCredited(invoiceItems);
+ return InvoiceCalculatorUtils.computeInvoiceAmountCredited(currency, invoiceItems);
}
@Override
public BigDecimal getRefundedAmount() {
- return InvoiceCalculatorUtils.computeInvoiceAmountRefunded(payments);
+ return InvoiceCalculatorUtils.computeInvoiceAmountRefunded(currency, payments);
}
@Override
public BigDecimal getBalance() {
- return InvoiceCalculatorUtils.computeInvoiceBalance(invoiceItems, payments);
+ return InvoiceCalculatorUtils.computeInvoiceBalance(currency, invoiceItems, payments);
}
@Override
diff --git a/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql b/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
index 50d736e..b8542c1 100644
--- a/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
+++ b/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
@@ -13,8 +13,8 @@ CREATE TABLE invoice_items (
phase_name varchar(50),
start_date date NOT NULL,
end_date date,
- amount numeric(10,4) NOT NULL,
- rate numeric(10,4) NULL,
+ amount numeric(15,9) NOT NULL,
+ rate numeric(15,9) NULL,
currency char(3) NOT NULL,
linked_item_id char(36),
created_by varchar(50) NOT NULL,
@@ -52,11 +52,11 @@ DROP TABLE IF EXISTS invoice_payments;
CREATE TABLE invoice_payments (
record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
id char(36) NOT NULL,
- type varchar(24) NOT NULL,
+ type varchar(24) NOT NULL,
invoice_id char(36) NOT NULL,
payment_id char(36),
payment_date datetime NOT NULL,
- amount numeric(10,4) NOT NULL,
+ amount numeric(15,9) NOT NULL,
currency char(3) NOT NULL,
processed_currency char(3) NOT NULL,
payment_cookie_id char(36) DEFAULT NULL,
diff --git a/invoice/src/test/java/com/ning/billing/invoice/api/invoice/TestDefaultInvoicePaymentApi.java b/invoice/src/test/java/com/ning/billing/invoice/api/invoice/TestDefaultInvoicePaymentApi.java
index b74c117..b6d6ac5 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/api/invoice/TestDefaultInvoicePaymentApi.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/api/invoice/TestDefaultInvoicePaymentApi.java
@@ -125,7 +125,7 @@ public class TestDefaultInvoicePaymentApi extends InvoiceTestSuiteWithEmbeddedDB
Assert.assertEquals(refund.getType(), InvoicePaymentType.REFUND);
// Verify the current invoice balance
- final BigDecimal newInvoiceBalance = invoicePaymentApi.getInvoice(invoice.getId(), callContext).getBalance().setScale(2, RoundingMode.HALF_UP);
- Assert.assertEquals(newInvoiceBalance.compareTo(finalInvoiceAmount.setScale(2, RoundingMode.HALF_UP)), 0);
+ final BigDecimal newInvoiceBalance = invoicePaymentApi.getInvoice(invoice.getId(), callContext).getBalance();
+ Assert.assertEquals(newInvoiceBalance.compareTo(finalInvoiceAmount), 0);
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/api/user/TestDefaultInvoiceUserApi.java b/invoice/src/test/java/com/ning/billing/invoice/api/user/TestDefaultInvoiceUserApi.java
index 634eb14..25e9c16 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/api/user/TestDefaultInvoiceUserApi.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/api/user/TestDefaultInvoiceUserApi.java
@@ -29,16 +29,17 @@ import org.testng.annotations.Test;
import com.ning.billing.ErrorCode;
import com.ning.billing.ObjectType;
import com.ning.billing.account.api.Account;
+import com.ning.billing.catalog.api.Currency;
import com.ning.billing.invoice.InvoiceTestSuiteWithEmbeddedDB;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceApiException;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoiceItemType;
-import com.ning.billing.invoice.model.InvoicingConfiguration;
import com.ning.billing.util.api.TagApiException;
import com.ning.billing.util.callcontext.CallContext;
import com.ning.billing.callcontext.DefaultCallContext;
import com.ning.billing.clock.ClockMock;
+import com.ning.billing.util.currency.KillBillMoney;
import com.ning.billing.util.tag.ControlTagType;
import com.ning.billing.util.tag.Tag;
@@ -238,7 +239,7 @@ public class TestDefaultInvoiceUserApi extends InvoiceTestSuiteWithEmbeddedDB {
// Verify the adjusted invoice balance
final BigDecimal adjustedInvoiceBalance = invoiceUserApi.getInvoice(invoiceId, callContext).getBalance();
- verifyAdjustedInvoiceBalance(invoiceBalance, creditAmount, adjustedInvoiceBalance);
+ verifyAdjustedInvoiceBalance(invoiceBalance, creditAmount, accountCurrency, adjustedInvoiceBalance);
// Verify the adjusted account balance
final BigDecimal adjustedAccountBalance = invoiceUserApi.getAccountBalance(accountId, callContext);
@@ -281,7 +282,7 @@ public class TestDefaultInvoiceUserApi extends InvoiceTestSuiteWithEmbeddedDB {
// Verify the adjusted invoice balance
final BigDecimal adjustedInvoiceBalance = invoiceUserApi.getInvoice(invoiceId, callContext).getBalance();
- verifyAdjustedInvoiceBalance(invoiceBalance, invoiceItem.getAmount(), adjustedInvoiceBalance);
+ verifyAdjustedInvoiceBalance(invoiceBalance, invoiceItem.getAmount(), invoiceItem.getCurrency(), adjustedInvoiceBalance);
// Verify the adjusted account balance
final BigDecimal adjustedAccountBalance = invoiceUserApi.getAccountBalance(accountId, callContext);
@@ -316,7 +317,7 @@ public class TestDefaultInvoiceUserApi extends InvoiceTestSuiteWithEmbeddedDB {
// Verify the adjusted invoice balance
final BigDecimal adjustedInvoiceBalance = invoiceUserApi.getInvoice(invoiceId, callContext).getBalance();
- verifyAdjustedInvoiceBalance(invoiceBalance, adjAmount, adjustedInvoiceBalance);
+ verifyAdjustedInvoiceBalance(invoiceBalance, adjAmount, accountCurrency, adjustedInvoiceBalance);
// Verify the adjusted account balance
final BigDecimal adjustedAccountBalance = invoiceUserApi.getAccountBalance(accountId, callContext);
@@ -336,10 +337,9 @@ public class TestDefaultInvoiceUserApi extends InvoiceTestSuiteWithEmbeddedDB {
}
}
- private void verifyAdjustedInvoiceBalance(final BigDecimal invoiceBalance, final BigDecimal adjAmount, final BigDecimal adjustedInvoiceBalance) {
- Assert.assertEquals(adjustedInvoiceBalance.compareTo(invoiceBalance.add(adjAmount.negate())
- .setScale(InvoicingConfiguration.getNumberOfDecimals(),
- InvoicingConfiguration.getRoundingMode())), 0);
+ private void verifyAdjustedInvoiceBalance(final BigDecimal invoiceBalance, final BigDecimal adjAmount, final Currency currency, final BigDecimal adjustedInvoiceBalance) {
+ final BigDecimal expectedBalance = KillBillMoney.of(invoiceBalance.add(adjAmount.negate()), currency);
+ Assert.assertEquals(adjustedInvoiceBalance.compareTo(expectedBalance), 0);
}
@Test(groups = "slow")
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceDao.java b/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceDao.java
index 0488412..540c8e3 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceDao.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceDao.java
@@ -67,6 +67,7 @@ import com.ning.billing.entity.EntityPersistenceException;
import com.ning.billing.junction.BillingEvent;
import com.ning.billing.junction.BillingEventSet;
import com.ning.billing.junction.BillingModeType;
+import com.ning.billing.util.currency.KillBillMoney;
import com.google.common.collect.ImmutableMap;
@@ -1099,7 +1100,7 @@ public class TestInvoiceDao extends InvoiceTestSuiteWithEmbeddedDB {
events.add(event1);
final Invoice invoice1 = generator.generateInvoice(accountId, events, invoiceList, targetDate, Currency.USD);
- assertEquals(invoice1.getBalance(), TEN);
+ assertEquals(invoice1.getBalance(), KillBillMoney.of(TEN, invoice1.getCurrency()));
invoiceList.add(invoice1);
// generate second invoice
@@ -1117,17 +1118,17 @@ public class TestInvoiceDao extends InvoiceTestSuiteWithEmbeddedDB {
// second invoice should be for one half (14/28 days) the difference between the rate plans
// this is a temporary state, since it actually contains an adjusting item that properly belong to invoice 1
final Invoice invoice2 = generator.generateInvoice(accountId, events, invoiceList, targetDate, Currency.USD);
- assertEquals(invoice2.getBalance(), FIVE);
+ assertEquals(invoice2.getBalance(), KillBillMoney.of(FIVE, invoice2.getCurrency()));
invoiceList.add(invoice2);
invoiceUtil.createInvoice(invoice1, true, context);
invoiceUtil.createInvoice(invoice2, true, context);
final InvoiceModelDao savedInvoice1 = invoiceDao.getById(invoice1.getId(), context);
- assertEquals(InvoiceModelDaoHelper.getBalance(savedInvoice1), FIVE);
+ assertEquals(InvoiceModelDaoHelper.getBalance(savedInvoice1), KillBillMoney.of(FIVE, savedInvoice1.getCurrency()));
final InvoiceModelDao savedInvoice2 = invoiceDao.getById(invoice2.getId(), context);
- assertEquals(InvoiceModelDaoHelper.getBalance(savedInvoice2), TEN);
+ assertEquals(InvoiceModelDaoHelper.getBalance(savedInvoice2), KillBillMoney.of(TEN, savedInvoice2.getCurrency()));
}
@Test(groups = "slow")
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceItemDao.java b/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceItemDao.java
index d1f25c3..dd6750e 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceItemDao.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/TestInvoiceItemDao.java
@@ -26,7 +26,9 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.ning.billing.account.api.Account;
+import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.entity.EntityPersistenceException;
import com.ning.billing.invoice.InvoiceTestSuiteWithEmbeddedDB;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.model.CreditBalanceAdjInvoiceItem;
@@ -35,8 +37,6 @@ import com.ning.billing.invoice.model.ExternalChargeInvoiceItem;
import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.model.InvoiceItemFactory;
import com.ning.billing.invoice.model.RecurringInvoiceItem;
-import com.ning.billing.callcontext.InternalCallContext;
-import com.ning.billing.entity.EntityPersistenceException;
import static com.ning.billing.invoice.TestInvoiceHelper.TEN;
import static org.testng.Assert.assertEquals;
@@ -191,6 +191,41 @@ public class TestInvoiceItemDao extends InvoiceTestSuiteWithEmbeddedDB {
assertSameInvoiceItem(externalChargeInvoiceItem, savedItem);
}
+ @Test(groups = "slow")
+ public void testExternalChargeForVariousCurrenciesInvoiceSqlDao() throws Exception {
+ // 1 decimal place
+ createAndVerifyExternalCharge(new BigDecimal("10"), Currency.VND);
+ createAndVerifyExternalCharge(new BigDecimal("10.1"), Currency.VND);
+ // 2 decimal places
+ createAndVerifyExternalCharge(new BigDecimal("10"), Currency.USD);
+ createAndVerifyExternalCharge(new BigDecimal("10.1"), Currency.USD);
+ createAndVerifyExternalCharge(new BigDecimal("10.01"), Currency.USD);
+ // 3 decimal places
+ createAndVerifyExternalCharge(new BigDecimal("10"), Currency.BHD);
+ createAndVerifyExternalCharge(new BigDecimal("10.1"), Currency.BHD);
+ createAndVerifyExternalCharge(new BigDecimal("10.01"), Currency.BHD);
+ createAndVerifyExternalCharge(new BigDecimal("10.001"), Currency.BHD);
+ // 8 decimal places
+ createAndVerifyExternalCharge(new BigDecimal("10"), Currency.BTC);
+ createAndVerifyExternalCharge(new BigDecimal("10.1"), Currency.BTC);
+ createAndVerifyExternalCharge(new BigDecimal("10.01"), Currency.BTC);
+ createAndVerifyExternalCharge(new BigDecimal("10.001"), Currency.BTC);
+ createAndVerifyExternalCharge(new BigDecimal("10.0001"), Currency.BTC);
+ createAndVerifyExternalCharge(new BigDecimal("10.00001"), Currency.BTC);
+ createAndVerifyExternalCharge(new BigDecimal("10.000001"), Currency.BTC);
+ createAndVerifyExternalCharge(new BigDecimal("10.0000001"), Currency.BTC);
+ createAndVerifyExternalCharge(new BigDecimal("10.00000001"), Currency.BTC);
+ }
+
+ private void createAndVerifyExternalCharge(final BigDecimal amount, final Currency currency) throws EntityPersistenceException {
+ final InvoiceItem externalChargeInvoiceItem = new ExternalChargeInvoiceItem(UUID.randomUUID(), account.getId(), UUID.randomUUID(),
+ UUID.randomUUID().toString(), new LocalDate(2012, 4, 1), amount, currency);
+ invoiceUtil.createInvoiceItem(externalChargeInvoiceItem, context);
+
+ final InvoiceItemModelDao savedItem = invoiceUtil.getInvoiceItemById(externalChargeInvoiceItem.getId(), context);
+ assertSameInvoiceItem(externalChargeInvoiceItem, savedItem);
+ Assert.assertEquals(externalChargeInvoiceItem.getAmount().compareTo(amount), 0);
+ }
private void assertSameInvoiceItem(final InvoiceItem initialItem, final InvoiceItemModelDao fromDao) {
final InvoiceItem newItem = InvoiceItemFactory.fromModelDao(fromDao);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
index fce3a9d..840d615 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
@@ -43,8 +43,8 @@ import com.ning.billing.catalog.api.Currency;
import com.ning.billing.catalog.api.PhaseType;
import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
-import com.ning.billing.subscription.api.SubscriptionBaseTransitionType;
-import com.ning.billing.subscription.api.SubscriptionBase;
+import com.ning.billing.clock.Clock;
+import com.ning.billing.clock.DefaultClock;
import com.ning.billing.invoice.InvoiceTestSuiteNoDB;
import com.ning.billing.invoice.MockBillingEventSet;
import com.ning.billing.invoice.api.Invoice;
@@ -54,12 +54,13 @@ import com.ning.billing.invoice.api.InvoicePaymentType;
import com.ning.billing.invoice.model.DefaultInvoicePayment;
import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
import com.ning.billing.invoice.model.RecurringInvoiceItem;
-import com.ning.billing.clock.Clock;
-import com.ning.billing.clock.DefaultClock;
-import com.ning.billing.util.config.InvoiceConfig;
import com.ning.billing.junction.BillingEvent;
import com.ning.billing.junction.BillingEventSet;
import com.ning.billing.junction.BillingModeType;
+import com.ning.billing.subscription.api.SubscriptionBase;
+import com.ning.billing.subscription.api.SubscriptionBaseTransitionType;
+import com.ning.billing.util.config.InvoiceConfig;
+import com.ning.billing.util.currency.KillBillMoney;
import static com.ning.billing.invoice.TestInvoiceHelper.EIGHT;
import static com.ning.billing.invoice.TestInvoiceHelper.FIFTEEN;
@@ -67,10 +68,8 @@ import static com.ning.billing.invoice.TestInvoiceHelper.FIVE;
import static com.ning.billing.invoice.TestInvoiceHelper.FORTY;
import static com.ning.billing.invoice.TestInvoiceHelper.FOURTEEN;
import static com.ning.billing.invoice.TestInvoiceHelper.NINETEEN;
-import static com.ning.billing.invoice.TestInvoiceHelper.NUMBER_OF_DECIMALS;
import static com.ning.billing.invoice.TestInvoiceHelper.ONE;
import static com.ning.billing.invoice.TestInvoiceHelper.ONE_HUNDRED;
-import static com.ning.billing.invoice.TestInvoiceHelper.ROUNDING_METHOD;
import static com.ning.billing.invoice.TestInvoiceHelper.TEN;
import static com.ning.billing.invoice.TestInvoiceHelper.THIRTEEN;
import static com.ning.billing.invoice.TestInvoiceHelper.THIRTY;
@@ -146,7 +145,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
assertNotNull(invoice);
assertEquals(invoice.getNumberOfItems(), 2);
- assertEquals(invoice.getBalance(), TWENTY);
+ assertEquals(invoice.getBalance(), KillBillMoney.of(TWENTY, invoice.getCurrency()));
assertEquals(invoice.getInvoiceItems().get(0).getSubscriptionId(), sub.getId());
}
@@ -233,8 +232,8 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
assertEquals(invoice.getNumberOfItems(), 2);
final BigDecimal expectedNumberOfBillingCycles;
- expectedNumberOfBillingCycles = ONE.add(FOURTEEN.divide(THIRTY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- final BigDecimal expectedAmount = expectedNumberOfBillingCycles.multiply(rate).setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedNumberOfBillingCycles = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
+ final BigDecimal expectedAmount = KillBillMoney.of(expectedNumberOfBillingCycles.multiply(rate), invoice.getCurrency());
assertEquals(invoice.getBalance(), expectedAmount);
}
@@ -264,7 +263,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
assertNotNull(invoice);
assertEquals(invoice.getNumberOfItems(), 2);
- assertEquals(invoice.getBalance(), rate1.add(rate2).setScale(NUMBER_OF_DECIMALS));
+ assertEquals(invoice.getBalance(), KillBillMoney.of(rate1.add(rate2), invoice.getCurrency()));
}
@Test(groups = "fast")
@@ -292,14 +291,14 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
assertEquals(invoice.getNumberOfItems(), 4);
final BigDecimal numberOfCyclesEvent1;
- numberOfCyclesEvent1 = ONE.add(FOURTEEN.divide(THIRTY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ numberOfCyclesEvent1 = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
final BigDecimal numberOfCyclesEvent2 = TWO;
BigDecimal expectedValue;
expectedValue = numberOfCyclesEvent1.multiply(rate1);
expectedValue = expectedValue.add(numberOfCyclesEvent2.multiply(rate2));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = KillBillMoney.of(expectedValue, invoice.getCurrency());
assertEquals(invoice.getBalance(), expectedValue);
}
@@ -332,7 +331,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
assertNotNull(invoice);
assertEquals(invoice.getNumberOfItems(), 4);
- assertEquals(invoice.getBalance(), rate1.add(rate2).add(TWO.multiply(rate3)).setScale(NUMBER_OF_DECIMALS));
+ assertEquals(invoice.getBalance(), KillBillMoney.of(rate1.add(rate2).add(TWO.multiply(rate3)), invoice.getCurrency()));
}
@Test(groups = "fast")
@@ -475,7 +474,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
// on 6/21/2011, create add-on (subscription 5)
events.add(createBillingEvent(subscriptionId5, bundleId, plan5StartDate, plan5, plan5Phase1, 10));
- expectedAmount = TWENTY.multiply(NINETEEN).divide(THIRTY, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedAmount = TWENTY.multiply(NINETEEN).divide(THIRTY, KillBillMoney.ROUNDING_METHOD);
testInvoiceGeneration(accountId, events, invoices, plan5StartDate, 1, expectedAmount);
// on 7/7/2011, invoice SubscriptionBase 4 (plan 1)
@@ -615,7 +614,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
final Invoice invoice1 = generator.generateInvoice(accountId, events, null, startDate, Currency.USD);
assertNotNull(invoice1);
assertEquals(invoice1.getNumberOfItems(), 2);
- assertEquals(invoice1.getBalance(), FIFTEEN);
+ assertEquals(invoice1.getBalance(), KillBillMoney.of(FIFTEEN, invoice1.getCurrency()));
final List<Invoice> invoiceList = new ArrayList<Invoice>();
invoiceList.add(invoice1);
@@ -627,7 +626,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
final Invoice invoice2 = generator.generateInvoice(accountId, events, invoiceList, currentDate, Currency.USD);
assertNotNull(invoice2);
assertEquals(invoice2.getNumberOfItems(), 1);
- assertEquals(invoice2.getBalance(), FIVE);
+ assertEquals(invoice2.getBalance(), KillBillMoney.of(FIVE, invoice2.getCurrency()));
}
@Test(groups = "fast")
@@ -652,7 +651,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
final Invoice invoice1 = generator.generateInvoice(accountId, events, null, startDate, Currency.USD);
assertNotNull(invoice1);
assertEquals(invoice1.getNumberOfItems(), 1);
- assertEquals(invoice1.getBalance(), fixedCost1);
+ assertEquals(invoice1.getBalance(), KillBillMoney.of(fixedCost1, invoice1.getCurrency()));
final List<Invoice> invoiceList = new ArrayList<Invoice>();
invoiceList.add(invoice1);
@@ -666,7 +665,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
final Invoice invoice2 = generator.generateInvoice(accountId, events, invoiceList, phaseChangeDate, Currency.USD);
assertNotNull(invoice2);
assertEquals(invoice2.getNumberOfItems(), 1);
- assertEquals(invoice2.getBalance(), fixedCost2);
+ assertEquals(invoice2.getBalance(), KillBillMoney.of(fixedCost2, invoice2.getCurrency()));
}
@Test(groups = "fast")
@@ -785,7 +784,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
existingInvoices.add(invoice);
distributeItems(existingInvoices);
- assertEquals(invoice.getBalance(), expectedAmount);
+ assertEquals(invoice.getBalance(), KillBillMoney.of(expectedAmount, invoice.getCurrency()));
}
@Test(groups = "fast")
@@ -831,7 +830,7 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
invoices.add(invoice2);
assertNotNull(invoice2);
assertEquals(invoice2.getNumberOfItems(), 2);
- assertEquals(invoice2.getBalance().compareTo(TWENTY_FIVE.multiply(new BigDecimal("0.9")).setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD)), 0);
+ assertEquals(invoice2.getBalance().compareTo(KillBillMoney.of(TWENTY_FIVE.multiply(new BigDecimal("0.9")), invoice2.getCurrency())), 0);
// perform a repair (change base plan; remove one add-on)
// event stream should include just two plans
@@ -851,7 +850,6 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
assertEquals(invoice3.getBalance().compareTo(FIFTEEN.negate()), 0);
}
-
@Test(groups = "fast")
public void testRepairForPaidInvoice() throws CatalogApiException, InvoiceApiException {
// create an invoice
@@ -1001,7 +999,6 @@ public class TestDefaultInvoiceGenerator extends InvoiceTestSuiteNoDB {
assertTrue(invoice3.getBalance().compareTo(FIFTEEN.multiply(TWO).add(TWELVE)) == 0);
}
-
private void printDetailInvoice(final Invoice invoice) {
log.info("-------------------- START DETAIL ----------------------");
log.info("Invoice " + invoice.getId() + ": BALANCE = " + invoice.getBalance()
diff --git a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorRepairUnit.java b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorRepairUnit.java
index c363267..3a5620d 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorRepairUnit.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorRepairUnit.java
@@ -195,13 +195,13 @@ public class TestDefaultInvoiceGeneratorRepairUnit extends InvoiceTestSuiteNoDB
assertEquals(proposed.get(0).getStartDate(), endDateProposed1);
assertEquals(proposed.get(0).getEndDate(), startDateProposed2);
assertEquals(proposed.get(0).getLinkedItemId(), repairedItem.getId());
- assertEquals(proposed.get(0).getAmount(), new BigDecimal("-69.894000"));
+ assertEquals(proposed.get(0).getAmount(), new BigDecimal("-69.89010993000"));
assertEquals(proposed.get(0).getInvoiceItemType(), InvoiceItemType.REPAIR_ADJ);
assertEquals(proposed.get(1).getStartDate(), endDateProposed2);
assertEquals(proposed.get(1).getEndDate(), startDateProposed3);
assertEquals(proposed.get(1).getLinkedItemId(), repairedItem.getId());
- assertEquals(proposed.get(1).getAmount(), new BigDecimal("-20.106000"));
+ assertEquals(proposed.get(1).getAmount(), new BigDecimal("-20.10989007000"));
assertEquals(proposed.get(1).getInvoiceItemType(), InvoiceItemType.REPAIR_ADJ);
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/generator/TestInvoiceDateUtils.java b/invoice/src/test/java/com/ning/billing/invoice/generator/TestInvoiceDateUtils.java
index 2ee9dff..58a0c32 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/generator/TestInvoiceDateUtils.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/generator/TestInvoiceDateUtils.java
@@ -49,7 +49,7 @@ public class TestInvoiceDateUtils extends InvoiceTestSuiteNoDB {
final LocalDate endDate = new LocalDate("2012-06-02");
final LocalDate previousBillThroughDate = new LocalDate("2012-03-02");
final BigDecimal proration = InvoiceDateUtils.calculateProRationAfterLastBillingCycleDate(endDate, previousBillThroughDate, BillingPeriod.MONTHLY);
- Assert.assertEquals(proration, new BigDecimal("2.9677"));
+ Assert.assertEquals(proration, new BigDecimal("2.967741935"));
}
@Test(groups = "fast")
diff --git a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
index 728bcce..6eb2a11 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
@@ -172,7 +172,7 @@ public class TestInvoiceDispatcher extends InvoiceTestSuiteWithEmbeddedDB {
Assert.assertEquals(invoiceItems.get(3).getInvoiceItemType(), InvoiceItemType.RECURRING);
Assert.assertEquals(invoiceItems.get(3).getStartDate(), new LocalDate("2012-07-25"));
Assert.assertEquals(invoiceItems.get(3).getEndDate(), new LocalDate("2012-07-31"));
- Assert.assertEquals(invoiceItems.get(3).getAmount(), new BigDecimal("193.50"));
+ Assert.assertEquals(invoiceItems.get(3).getAmount(), new BigDecimal("193.55"));
Assert.assertEquals(invoiceItems.get(3).getRate(), new BigDecimal("1000"));
// Verify common fields
diff --git a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceHelper.java b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceHelper.java
index 17c2f2c..dd63ced 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceHelper.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceHelper.java
@@ -33,7 +33,10 @@ import org.testng.Assert;
import com.ning.billing.account.api.Account;
import com.ning.billing.account.api.AccountApiException;
import com.ning.billing.account.api.AccountData;
+import com.ning.billing.account.api.AccountInternalApi;
import com.ning.billing.account.api.AccountUserApi;
+import com.ning.billing.callcontext.InternalCallContext;
+import com.ning.billing.callcontext.InternalTenantContext;
import com.ning.billing.catalog.MockPlan;
import com.ning.billing.catalog.MockPlanPhase;
import com.ning.billing.catalog.api.BillingPeriod;
@@ -42,6 +45,7 @@ import com.ning.billing.catalog.api.Plan;
import com.ning.billing.catalog.api.PlanPhase;
import com.ning.billing.clock.Clock;
import com.ning.billing.commons.locker.GlobalLocker;
+import com.ning.billing.entity.EntityPersistenceException;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceApiException;
import com.ning.billing.invoice.api.InvoiceItem;
@@ -55,24 +59,20 @@ import com.ning.billing.invoice.dao.InvoiceModelDaoHelper;
import com.ning.billing.invoice.dao.InvoicePaymentModelDao;
import com.ning.billing.invoice.dao.InvoicePaymentSqlDao;
import com.ning.billing.invoice.generator.InvoiceGenerator;
-import com.ning.billing.invoice.model.InvoicingConfiguration;
import com.ning.billing.invoice.notification.NullInvoiceNotifier;
+import com.ning.billing.junction.BillingEvent;
+import com.ning.billing.junction.BillingEventSet;
+import com.ning.billing.junction.BillingInternalApi;
+import com.ning.billing.junction.BillingModeType;
import com.ning.billing.mock.MockAccountBuilder;
import com.ning.billing.subscription.api.SubscriptionBase;
+import com.ning.billing.subscription.api.SubscriptionBaseInternalApi;
import com.ning.billing.subscription.api.SubscriptionBaseTransitionType;
import com.ning.billing.subscription.api.user.SubscriptionBaseApiException;
import com.ning.billing.util.callcontext.CallContext;
-import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalCallContextFactory;
-import com.ning.billing.callcontext.InternalTenantContext;
+import com.ning.billing.util.currency.KillBillMoney;
import com.ning.billing.util.dao.NonEntityDao;
-import com.ning.billing.entity.EntityPersistenceException;
-import com.ning.billing.account.api.AccountInternalApi;
-import com.ning.billing.junction.BillingEvent;
-import com.ning.billing.junction.BillingEventSet;
-import com.ning.billing.junction.BillingInternalApi;
-import com.ning.billing.junction.BillingModeType;
-import com.ning.billing.subscription.api.SubscriptionBaseInternalApi;
import com.ning.billing.util.svcsapi.bus.BusService;
import com.google.common.base.Function;
@@ -84,51 +84,48 @@ public class TestInvoiceHelper {
public static final Currency accountCurrency = Currency.USD;
- public static final int NUMBER_OF_DECIMALS = InvoicingConfiguration.getNumberOfDecimals();
- public static final int ROUNDING_METHOD = InvoicingConfiguration.getRoundingMode();
-
- public static final BigDecimal ZERO = new BigDecimal("0.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal ONE_HALF = new BigDecimal("0.5").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal ONE = new BigDecimal("1.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal ONE_AND_A_HALF = new BigDecimal("1.5").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal TWO = new BigDecimal("2.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal THREE = new BigDecimal("3.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal FOUR = new BigDecimal("4.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal FIVE = new BigDecimal("5.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal SIX = new BigDecimal("6.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal SEVEN = new BigDecimal("7.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal EIGHT = new BigDecimal("8.0").setScale(NUMBER_OF_DECIMALS);
-
- public static final BigDecimal TEN = new BigDecimal("10.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal ELEVEN = new BigDecimal("11.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal TWELVE = new BigDecimal("12.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal THIRTEEN = new BigDecimal("13.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal FOURTEEN = new BigDecimal("14.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal FIFTEEN = new BigDecimal("15.0").setScale(NUMBER_OF_DECIMALS);
-
- public static final BigDecimal NINETEEN = new BigDecimal("19.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal TWENTY = new BigDecimal("20.0").setScale(NUMBER_OF_DECIMALS);
-
- public static final BigDecimal TWENTY_FOUR = new BigDecimal("24.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal TWENTY_FIVE = new BigDecimal("25.0").setScale(NUMBER_OF_DECIMALS);
-
- public static final BigDecimal TWENTY_SEVEN = new BigDecimal("27.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal TWENTY_EIGHT = new BigDecimal("28.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal TWENTY_NINE = new BigDecimal("29.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal THIRTY = new BigDecimal("30.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal THIRTY_ONE = new BigDecimal("31.0").setScale(NUMBER_OF_DECIMALS);
-
- public static final BigDecimal FORTY = new BigDecimal("40.0").setScale(NUMBER_OF_DECIMALS);
-
- public static final BigDecimal EIGHTY_NINE = new BigDecimal("89.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal NINETY = new BigDecimal("90.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal NINETY_ONE = new BigDecimal("91.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal NINETY_TWO = new BigDecimal("92.0").setScale(NUMBER_OF_DECIMALS);
-
- public static final BigDecimal ONE_HUNDRED = new BigDecimal("100.0").setScale(NUMBER_OF_DECIMALS);
-
- public static final BigDecimal THREE_HUNDRED_AND_SIXTY_FIVE = new BigDecimal("365.0").setScale(NUMBER_OF_DECIMALS);
- public static final BigDecimal THREE_HUNDRED_AND_SIXTY_SIX = new BigDecimal("366.0").setScale(NUMBER_OF_DECIMALS);
+ public static final BigDecimal ZERO = new BigDecimal("0.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal ONE_HALF = new BigDecimal("0.5").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal ONE = new BigDecimal("1.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal ONE_AND_A_HALF = new BigDecimal("1.5").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal TWO = new BigDecimal("2.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal THREE = new BigDecimal("3.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal FOUR = new BigDecimal("4.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal FIVE = new BigDecimal("5.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal SIX = new BigDecimal("6.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal SEVEN = new BigDecimal("7.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal EIGHT = new BigDecimal("8.0").setScale(KillBillMoney.MAX_SCALE);
+
+ public static final BigDecimal TEN = new BigDecimal("10.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal ELEVEN = new BigDecimal("11.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal TWELVE = new BigDecimal("12.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal THIRTEEN = new BigDecimal("13.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal FOURTEEN = new BigDecimal("14.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal FIFTEEN = new BigDecimal("15.0").setScale(KillBillMoney.MAX_SCALE);
+
+ public static final BigDecimal NINETEEN = new BigDecimal("19.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal TWENTY = new BigDecimal("20.0").setScale(KillBillMoney.MAX_SCALE);
+
+ public static final BigDecimal TWENTY_FOUR = new BigDecimal("24.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal TWENTY_FIVE = new BigDecimal("25.0").setScale(KillBillMoney.MAX_SCALE);
+
+ public static final BigDecimal TWENTY_SEVEN = new BigDecimal("27.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal TWENTY_EIGHT = new BigDecimal("28.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal TWENTY_NINE = new BigDecimal("29.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal THIRTY = new BigDecimal("30.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal THIRTY_ONE = new BigDecimal("31.0").setScale(KillBillMoney.MAX_SCALE);
+
+ public static final BigDecimal FORTY = new BigDecimal("40.0").setScale(KillBillMoney.MAX_SCALE);
+
+ public static final BigDecimal EIGHTY_NINE = new BigDecimal("89.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal NINETY = new BigDecimal("90.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal NINETY_ONE = new BigDecimal("91.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal NINETY_TWO = new BigDecimal("92.0").setScale(KillBillMoney.MAX_SCALE);
+
+ public static final BigDecimal ONE_HUNDRED = new BigDecimal("100.0").setScale(KillBillMoney.MAX_SCALE);
+
+ public static final BigDecimal THREE_HUNDRED_AND_SIXTY_FIVE = new BigDecimal("365.0").setScale(KillBillMoney.MAX_SCALE);
+ public static final BigDecimal THREE_HUNDRED_AND_SIXTY_SIX = new BigDecimal("366.0").setScale(KillBillMoney.MAX_SCALE);
private final InvoiceGenerator generator;
private final BillingInternalApi billingApi;
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java
index 0cb0320..cc7485e 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestDoubleProRation.java
@@ -16,8 +16,6 @@
package com.ning.billing.invoice.tests.inAdvance.annual;
-import static com.ning.billing.invoice.TestInvoiceHelper.*;
-
import java.math.BigDecimal;
import org.joda.time.LocalDate;
@@ -26,6 +24,14 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
+
+import static com.ning.billing.invoice.TestInvoiceHelper.FOURTEEN;
+import static com.ning.billing.invoice.TestInvoiceHelper.ONE;
+import static com.ning.billing.invoice.TestInvoiceHelper.THREE_HUNDRED_AND_SIXTY_FIVE;
+import static com.ning.billing.invoice.TestInvoiceHelper.THREE_HUNDRED_AND_SIXTY_SIX;
+import static com.ning.billing.invoice.TestInvoiceHelper.TWELVE;
+import static com.ning.billing.invoice.TestInvoiceHelper.TWO;
public class TestDoubleProRation extends ProRationInAdvanceTestBase {
@@ -40,7 +46,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
- final BigDecimal expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -50,7 +56,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 7);
final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
- final BigDecimal expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -60,7 +66,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 15);
final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
- final BigDecimal expectedValue = ONE.add(FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -71,7 +77,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
@@ -84,10 +90,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -99,10 +104,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -114,10 +118,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -129,10 +132,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -144,7 +146,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2013, 4, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(TWO);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java
index 7fb9da3..d1b948a 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestLeadingProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestLeadingProRation extends ProRationInAdvanceTestBase {
@@ -40,7 +41,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 1);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -51,7 +52,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 4);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -62,7 +63,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -73,7 +74,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -85,7 +86,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -97,7 +98,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -109,7 +110,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -121,7 +122,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -133,7 +134,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -145,7 +146,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2012, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestProRation.java
index dde0beb..3349840 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestProRation extends ProRationInAdvanceTestBase {
@@ -39,7 +40,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 31);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 24);
- final BigDecimal expectedValue = ONE.add(FIFTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(FIFTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, targetDate, 15, expectedValue);
}
@@ -48,7 +49,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate startDate = invoiceUtil.buildDate(2010, 12, 15);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 13);
- final BigDecimal expectedValue = ONE.add(TWENTY.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(TWENTY.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, targetDate, 4, expectedValue);
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java
index 8f481f3..1fdbd65 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/annual/TestTrailingProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestTrailingProRation extends ProRationInAdvanceTestBase {
@@ -58,7 +59,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 6, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 6, 17);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(THREE_HUNDRED_AND_SIXTY_FIVE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
@@ -68,7 +69,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 6, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 6, 18);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(THREE_HUNDRED_AND_SIXTY_SIX, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
@@ -77,7 +78,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate startDate = invoiceUtil.buildDate(2010, 6, 17);
final LocalDate endDate = invoiceUtil.buildDate(2011, 6, 25);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(THREE_HUNDRED_AND_SIXTY_SIX, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, endDate, 17, expectedValue);
}
@@ -87,7 +88,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 6, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 7, 30);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(THREE_HUNDRED_AND_SIXTY_SIX, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java
index a3a5e9a..c8fbbf5 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/GenericProRationTestBase.java
@@ -24,6 +24,7 @@ import org.joda.time.LocalDate;
import org.testng.annotations.Test;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
+import com.ning.billing.util.currency.KillBillMoney;
public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBase {
@@ -131,7 +132,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate endDate = invoiceUtil.buildDate(2011, 1, 15);
- final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
@@ -141,7 +142,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 7);
final LocalDate endDate = invoiceUtil.buildDate(2011, 1, 15);
- final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
@@ -151,7 +152,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 15);
final LocalDate endDate = invoiceUtil.buildDate(2011, 1, 15);
- final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
@@ -161,7 +162,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 17);
final LocalDate endDate = invoiceUtil.buildDate(2011, 1, 15);
- final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
@@ -171,7 +172,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 1);
final LocalDate endDate = invoiceUtil.buildDate(2011, 1, 15);
- final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
@@ -181,7 +182,7 @@ public abstract class GenericProRationTestBase extends ProRationInAdvanceTestBas
final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 5);
final LocalDate endDate = invoiceUtil.buildDate(2011, 1, 15);
- final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(getDaysInTestPeriod(), KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java
index 79fd1cd..77b63b7 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestDoubleProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestDoubleProRation extends ProRationInAdvanceTestBase {
@@ -40,7 +41,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
- final BigDecimal expectedValue = FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -50,7 +51,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 7);
final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
- final BigDecimal expectedValue = FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -60,7 +61,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 15);
final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
- final BigDecimal expectedValue = ONE.add(FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -71,7 +72,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
@@ -84,9 +85,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -98,9 +99,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -112,9 +113,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -126,9 +127,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -140,7 +141,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(TWO);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java
index 1a6224f..96dcc63 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestLeadingProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestLeadingProRation extends ProRationInAdvanceTestBase {
@@ -40,7 +41,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 1);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -51,7 +52,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 4);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -62,7 +63,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -73,7 +74,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(THREE);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD).add(THREE);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -85,7 +86,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -97,7 +98,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -109,7 +110,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -121,7 +122,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -133,7 +134,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -145,7 +146,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = TWELVE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java
index 15806dd..7a28ebd 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestProRation.java
@@ -16,8 +16,6 @@
package com.ning.billing.invoice.tests.inAdvance.monthly;
-import static com.ning.billing.invoice.TestInvoiceHelper.*;
-
import java.math.BigDecimal;
import org.joda.time.LocalDate;
@@ -26,6 +24,21 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
+
+import static com.ning.billing.invoice.TestInvoiceHelper.EIGHT;
+import static com.ning.billing.invoice.TestInvoiceHelper.FIVE;
+import static com.ning.billing.invoice.TestInvoiceHelper.FOURTEEN;
+import static com.ning.billing.invoice.TestInvoiceHelper.ONE;
+import static com.ning.billing.invoice.TestInvoiceHelper.ONE_AND_A_HALF;
+import static com.ning.billing.invoice.TestInvoiceHelper.ONE_HALF;
+import static com.ning.billing.invoice.TestInvoiceHelper.SEVEN;
+import static com.ning.billing.invoice.TestInvoiceHelper.THIRTEEN;
+import static com.ning.billing.invoice.TestInvoiceHelper.THIRTY_ONE;
+import static com.ning.billing.invoice.TestInvoiceHelper.THREE;
+import static com.ning.billing.invoice.TestInvoiceHelper.TWENTY_EIGHT;
+import static com.ning.billing.invoice.TestInvoiceHelper.TWENTY_NINE;
+import static com.ning.billing.invoice.TestInvoiceHelper.TWO;
public class TestProRation extends ProRationInAdvanceTestBase {
@@ -134,10 +147,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
BigDecimal expectedValue;
- expectedValue = THIRTEEN.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = THIRTEEN.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
- expectedValue = ONE.add(FOURTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 31, expectedValue);
}
@@ -149,10 +162,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
BigDecimal expectedValue;
- expectedValue = THIRTEEN.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = THIRTEEN.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
- expectedValue = ONE.add(THIRTEEN.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = ONE.add(THIRTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 27, expectedValue);
}
@@ -163,7 +176,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2012, 2, 19);
final BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(TWENTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(TWENTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
@@ -176,7 +189,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final BigDecimal expectedValue;
- expectedValue = EIGHT.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = EIGHT.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, expectedValue);
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, THREE);
@@ -191,7 +204,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, ONE);
final BigDecimal expectedValue;
- expectedValue = EIGHT.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = EIGHT.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}
@@ -203,10 +216,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
BigDecimal expectedValue;
- expectedValue = BigDecimal.ONE.add(THREE.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = BigDecimal.ONE.add(THREE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, expectedValue);
- expectedValue = FIVE.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = FIVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}
@@ -217,13 +230,12 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 21);
BigDecimal expectedValue;
- expectedValue = SEVEN.divide(THIRTY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = SEVEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(THREE.divide(THIRTY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(THREE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 7, expectedValue);
- expectedValue = FIVE.divide(TWENTY_EIGHT, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = FIVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, expectedValue);
}
@@ -233,7 +245,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 15);
final LocalDate endDate = invoiceUtil.buildDate(2011, 3, 17);
- final BigDecimal expectedValue = THREE.add(TWO.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = THREE.add(TWO.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java
index 6cd7aec..2143bd4 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/monthly/TestTrailingProRation.java
@@ -16,8 +16,6 @@
package com.ning.billing.invoice.tests.inAdvance.monthly;
-import static com.ning.billing.invoice.TestInvoiceHelper.*;
-
import java.math.BigDecimal;
import org.joda.time.LocalDate;
@@ -26,6 +24,11 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
+
+import static com.ning.billing.invoice.TestInvoiceHelper.EIGHT;
+import static com.ning.billing.invoice.TestInvoiceHelper.ONE;
+import static com.ning.billing.invoice.TestInvoiceHelper.THIRTY_ONE;
public class TestTrailingProRation extends ProRationInAdvanceTestBase {
@@ -58,7 +61,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2010, 7, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2010, 7, 17);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
@@ -68,7 +71,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2010, 7, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2010, 7, 18);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
@@ -77,7 +80,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate startDate = invoiceUtil.buildDate(2010, 6, 17);
final LocalDate endDate = invoiceUtil.buildDate(2010, 7, 25);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, endDate, 17, expectedValue);
}
@@ -87,7 +90,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2010, 7, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2010, 7, 30);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(THIRTY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java
index 84744d1..096edd6 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestDoubleProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestDoubleProRation extends ProRationInAdvanceTestBase {
@@ -40,8 +41,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 1);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
- BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -51,8 +51,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 7);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
- BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ BigDecimal expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -62,8 +61,7 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 15);
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
- BigDecimal expectedValue = ONE.add(FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ BigDecimal expectedValue = ONE.add(FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -74,9 +72,8 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -88,10 +85,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -103,10 +99,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -118,10 +113,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -133,10 +127,9 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
@@ -148,9 +141,8 @@ public class TestDoubleProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 27);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(NINETY_TWO, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(TWO);
- expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java
index be8c394..c17d61f 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestLeadingProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestLeadingProRation extends ProRationInAdvanceTestBase {
@@ -40,7 +41,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 1);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -51,7 +52,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 4);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -62,7 +63,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -73,7 +74,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 6, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(startDate, targetDate, 13, expectedValue);
}
@@ -85,7 +86,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -97,7 +98,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -109,7 +110,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -121,7 +122,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -133,7 +134,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
@@ -145,7 +146,7 @@ public class TestLeadingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 13);
final BigDecimal expectedValue;
- expectedValue = TWELVE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = TWELVE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 13, expectedValue);
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java
index ce3608e..1e52e8b 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestProRation extends ProRationInAdvanceTestBase {
@@ -41,10 +42,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 6);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, phaseChangeDate, targetDate, 10, expectedValue);
- expectedValue = FOURTEEN.divide(NINETY, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 10, expectedValue);
}
@@ -55,10 +56,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 1);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, phaseChangeDate, targetDate, 3, expectedValue);
- expectedValue = FOURTEEN.divide(NINETY, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, expectedValue);
}
@@ -69,10 +70,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 3);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, phaseChangeDate, targetDate, 3, expectedValue);
- expectedValue = FOURTEEN.divide(NINETY, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = FOURTEEN.divide(NINETY, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, expectedValue);
}
@@ -83,10 +84,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 4);
BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, phaseChangeDate, targetDate, 3, expectedValue);
- expectedValue = FOURTEEN.divide(NINETY, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = FOURTEEN.divide(NINETY, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, expectedValue);
}
@@ -96,7 +97,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate planChangeDate = invoiceUtil.buildDate(2011, 2, 15);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 1);
- final BigDecimal expectedValue = FOURTEEN.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, ONE);
}
@@ -107,7 +108,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate planChangeDate = invoiceUtil.buildDate(2011, 3, 6);
final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 9);
- final BigDecimal expectedValue = FOURTEEN.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ final BigDecimal expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 20, expectedValue);
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 6, ONE);
}
@@ -152,10 +153,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
BigDecimal expectedValue;
- expectedValue = THIRTEEN.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = THIRTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
- expectedValue = ONE.add(FOURTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = ONE.add(FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 31, expectedValue);
}
@@ -167,10 +168,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
BigDecimal expectedValue;
- expectedValue = THIRTEEN.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = THIRTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
- expectedValue = ONE.add(THIRTEEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = ONE.add(THIRTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 27, expectedValue);
}
@@ -181,7 +182,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2012, 2, 19);
final BigDecimal expectedValue;
- expectedValue = FOURTEEN.divide(NINETY, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = FOURTEEN.divide(NINETY, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 1, expectedValue);
}
@@ -194,7 +195,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final BigDecimal expectedValue;
- expectedValue = EIGHT.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = EIGHT.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, expectedValue);
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, THREE);
@@ -209,7 +210,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, ONE);
final BigDecimal expectedValue;
- expectedValue = EIGHT.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = EIGHT.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}
@@ -221,10 +222,10 @@ public class TestProRation extends ProRationInAdvanceTestBase {
BigDecimal expectedValue;
- expectedValue = ONE.add(THREE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = ONE.add(THREE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, expectedValue);
- expectedValue = FIVE.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(TWO);
+ expectedValue = FIVE.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD).add(TWO);
testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}
@@ -235,12 +236,12 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 5, 21);
BigDecimal expectedValue;
- expectedValue = SEVEN.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ expectedValue = SEVEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
expectedValue = expectedValue.add(ONE);
- expectedValue = expectedValue.add(THREE.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ expectedValue = expectedValue.add(THREE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 7, expectedValue);
- expectedValue = FIVE.divide(EIGHTY_NINE, NUMBER_OF_DECIMALS, ROUNDING_METHOD).add(ONE);
+ expectedValue = FIVE.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD).add(ONE);
testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, expectedValue);
}
@@ -250,7 +251,7 @@ public class TestProRation extends ProRationInAdvanceTestBase {
final LocalDate targetDate = invoiceUtil.buildDate(2011, 6, 15);
final LocalDate endDate = invoiceUtil.buildDate(2011, 6, 17);
- final BigDecimal expectedValue = TWO.add(TWO.divide(NINETY_TWO, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = TWO.add(TWO.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java
index a9d6f4e..fdbea1c 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/quarterly/TestTrailingProRation.java
@@ -26,6 +26,7 @@ import org.testng.annotations.Test;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.invoice.model.InvalidDateSequenceException;
import com.ning.billing.invoice.tests.inAdvance.ProRationInAdvanceTestBase;
+import com.ning.billing.util.currency.KillBillMoney;
public class TestTrailingProRation extends ProRationInAdvanceTestBase {
@@ -58,7 +59,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2010, 9, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2010, 9, 17);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(NINETY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
@@ -68,7 +69,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2010, 9, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2010, 9, 18);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(NINETY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
@@ -77,7 +78,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate startDate = invoiceUtil.buildDate(2010, 6, 17);
final LocalDate endDate = invoiceUtil.buildDate(2010, 9, 25);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(NINETY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, endDate, 17, expectedValue);
}
@@ -87,7 +88,7 @@ public class TestTrailingProRation extends ProRationInAdvanceTestBase {
final LocalDate endDate = invoiceUtil.buildDate(2010, 9, 25);
final LocalDate targetDate = invoiceUtil.buildDate(2010, 9, 30);
- final BigDecimal expectedValue = ONE.add(EIGHT.divide(NINETY_ONE, NUMBER_OF_DECIMALS, ROUNDING_METHOD));
+ final BigDecimal expectedValue = ONE.add(EIGHT.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java
index 72d3658..71a66c9 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/inAdvance/TestValidationProRation.java
@@ -86,13 +86,5 @@ public class TestValidationProRation extends ProRationTestBase {
calculateNumberOfBillingCycles(startDate, targetDate, 15);
}
-
- @Test(groups = "fast")
- public void testBigDecimalTruncation() {
- final BigDecimal value = new BigDecimal("1.3349573498567");
- final BigDecimal truncated = value.setScale(0, BigDecimal.ROUND_DOWN).setScale(NUMBER_OF_DECIMALS);
-
- assertEquals(truncated, ONE);
- }
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/ProRationTestBase.java b/invoice/src/test/java/com/ning/billing/invoice/tests/ProRationTestBase.java
index 22775be..87c1bc9 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/ProRationTestBase.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/ProRationTestBase.java
@@ -72,7 +72,7 @@ public abstract class ProRationTestBase extends InvoiceTestSuiteNoDB {
numberOfBillingCycles = numberOfBillingCycles.add(item.getNumberOfCycles());
}
- return numberOfBillingCycles.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ return numberOfBillingCycles;
}
protected BigDecimal calculateNumberOfBillingCycles(final LocalDate startDate, final LocalDate targetDate, final int billingCycleDay) throws InvalidDateSequenceException {
@@ -83,6 +83,6 @@ public abstract class ProRationTestBase extends InvoiceTestSuiteNoDB {
numberOfBillingCycles = numberOfBillingCycles.add(item.getNumberOfCycles());
}
- return numberOfBillingCycles.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
+ return numberOfBillingCycles;
}
}
diff --git a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
index 4c6d3cc..8178f38 100644
--- a/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
+++ b/payment/src/main/java/com/ning/billing/payment/core/PaymentProcessor.java
@@ -459,8 +459,7 @@ public class PaymentProcessor extends ProcessorBase {
throw new PaymentApiException(ErrorCode.PAYMENT_AMOUNT_DENIED,
invoice.getId(), inputAmount.floatValue(), invoice.getBalance().floatValue());
}
- final BigDecimal result = inputAmount != null ? inputAmount : invoice.getBalance();
- return result.setScale(2, RoundingMode.HALF_UP);
+ return inputAmount != null ? inputAmount : invoice.getBalance();
}
public void retryAutoPayOff(final UUID paymentId, final InternalCallContext context) {
@@ -578,7 +577,7 @@ public class PaymentProcessor extends ProcessorBase {
private Payment processNewPaymentWithAccountLocked(final UUID paymentMethodId, final PaymentPluginApi plugin, final Account account, final Invoice invoice,
final BigDecimal requestedAmount, final boolean isInstantPayment, final InternalCallContext context) throws PaymentApiException {
- final PaymentModelDao payment = new PaymentModelDao(account.getId(), invoice.getId(), paymentMethodId, requestedAmount.setScale(2, RoundingMode.HALF_UP), invoice.getCurrency(), clock.getUTCNow());
+ final PaymentModelDao payment = new PaymentModelDao(account.getId(), invoice.getId(), paymentMethodId, requestedAmount, invoice.getCurrency(), clock.getUTCNow());
final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(account.getId(), invoice.getId(), payment.getId(), paymentMethodId, clock.getUTCNow(),
requestedAmount, invoice.getCurrency());
diff --git a/payment/src/main/resources/com/ning/billing/payment/ddl.sql b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
index ad2ee70..d37c010 100644
--- a/payment/src/main/resources/com/ning/billing/payment/ddl.sql
+++ b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
@@ -7,9 +7,9 @@ CREATE TABLE payments (
account_id char(36) NOT NULL,
invoice_id char(36) NOT NULL,
payment_method_id char(36) NOT NULL,
- amount numeric(10,4),
+ amount numeric(15,9),
currency char(3),
- processed_amount numeric(10,4),
+ processed_amount numeric(15,9),
processed_currency char(3),
effective_date datetime,
payment_status varchar(50),
@@ -26,7 +26,7 @@ CREATE INDEX payments_inv ON payments(invoice_id);
CREATE INDEX payments_accnt ON payments(account_id);
CREATE INDEX payments_tenant_account_record_id ON payments(tenant_record_id, account_record_id);
-DROP TABLE IF EXISTS payment_history;
+DROP TABLE IF EXISTS payment_history;
CREATE TABLE payment_history (
record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
id char(36) NOT NULL,
@@ -34,14 +34,14 @@ CREATE TABLE payment_history (
account_id char(36) NOT NULL,
invoice_id char(36) NOT NULL,
payment_method_id char(36) NOT NULL,
- amount numeric(10,4),
- currency char(3),
- processed_amount numeric(10,4),
+ amount numeric(15,9),
+ currency char(3),
+ processed_amount numeric(15,9),
processed_currency char(3),
effective_date datetime,
payment_status varchar(50),
ext_first_payment_ref_id varchar(128),
- ext_second_payment_ref_id varchar(128),
+ ext_second_payment_ref_id varchar(128),
change_type char(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
@@ -60,10 +60,10 @@ CREATE TABLE payment_attempts (
id char(36) NOT NULL,
payment_id char(36) NOT NULL,
payment_method_id char(36) NOT NULL,
- gateway_error_code varchar(32),
+ gateway_error_code varchar(32),
gateway_error_msg varchar(256),
processing_status varchar(50),
- requested_amount numeric(10,4),
+ requested_amount numeric(15,9),
requested_currency char(3),
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
@@ -84,10 +84,10 @@ CREATE TABLE payment_attempt_history (
target_record_id int(11) unsigned NOT NULL,
payment_id char(36) NOT NULL,
payment_method_id char(36) NOT NULL,
- gateway_error_code varchar(32),
+ gateway_error_code varchar(32),
gateway_error_msg varchar(256),
processing_status varchar(50),
- requested_amount numeric(10,4),
+ requested_amount numeric(15,9),
requested_currency char(3),
change_type char(6) NOT NULL,
created_by varchar(50) NOT NULL,
@@ -107,7 +107,7 @@ CREATE TABLE payment_methods (
id char(36) NOT NULL,
account_id char(36) NOT NULL,
plugin_name varchar(50) DEFAULT NULL,
- is_active bool DEFAULT true,
+ is_active bool DEFAULT true,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
@@ -127,7 +127,7 @@ CREATE TABLE payment_method_history (
target_record_id int(11) unsigned NOT NULL,
account_id char(36) NOT NULL,
plugin_name varchar(50) DEFAULT NULL,
- is_active bool DEFAULT true,
+ is_active bool DEFAULT true,
change_type char(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
@@ -140,18 +140,18 @@ CREATE TABLE payment_method_history (
CREATE INDEX payment_method_history_target_record_id ON payment_method_history(target_record_id);
CREATE INDEX payment_method_history_tenant_account_record_id ON payment_method_history(tenant_record_id, account_record_id);
-DROP TABLE IF EXISTS refunds;
+DROP TABLE IF EXISTS refunds;
CREATE TABLE refunds (
record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
id char(36) NOT NULL,
account_id char(36) NOT NULL,
payment_id char(36) NOT NULL,
- amount numeric(10,4),
+ amount numeric(15,9),
currency char(3),
- processed_amount numeric(10,4),
+ processed_amount numeric(15,9),
processed_currency char(3),
is_adjusted tinyint(1),
- refund_status varchar(50),
+ refund_status varchar(50),
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
@@ -165,19 +165,19 @@ CREATE INDEX refunds_pay ON refunds(payment_id);
CREATE INDEX refunds_accnt ON refunds(account_id);
CREATE INDEX refunds_tenant_account_record_id ON refunds(tenant_record_id, account_record_id);
-DROP TABLE IF EXISTS refund_history;
+DROP TABLE IF EXISTS refund_history;
CREATE TABLE refund_history (
record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
id char(36) NOT NULL,
target_record_id int(11) unsigned NOT NULL,
account_id char(36) NOT NULL,
payment_id char(36) NOT NULL,
- amount numeric(10,4),
+ amount numeric(15,9),
currency char(3),
- processed_amount numeric(10,4),
+ processed_amount numeric(15,9),
processed_currency char(3),
is_adjusted tinyint(1),
- refund_status varchar(50),
+ refund_status varchar(50),
change_type char(6) NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
diff --git a/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApiNoDB.java b/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApiNoDB.java
index 32938da..fdc3632 100644
--- a/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApiNoDB.java
+++ b/payment/src/test/java/com/ning/billing/payment/api/TestPaymentApiNoDB.java
@@ -121,7 +121,7 @@ public class TestPaymentApiNoDB extends PaymentTestSuiteNoDB {
fail("Expected to fail because requested amount > invoice amount");
}
assertNotNull(paymentInfo.getId());
- assertTrue(paymentInfo.getAmount().compareTo(expectedAmount.setScale(2, RoundingMode.HALF_EVEN)) == 0);
+ assertTrue(paymentInfo.getAmount().compareTo(expectedAmount) == 0);
assertNotNull(paymentInfo.getPaymentNumber());
assertEquals(paymentInfo.getPaymentStatus(), PaymentStatus.SUCCESS);
assertEquals(paymentInfo.getAttempts().size(), 1);
diff --git a/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java b/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
index 49717e9..3316300 100644
--- a/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
+++ b/payment/src/test/java/com/ning/billing/payment/dao/TestPaymentDao.java
@@ -207,7 +207,7 @@ public class TestPaymentDao extends PaymentTestSuiteWithEmbeddedDB {
clock.addDays(3);
final DateTime newEffectiveDate = clock.getUTCNow();
final UUID newPaymentMethodId = UUID.randomUUID();
- final BigDecimal newAmount = new BigDecimal(15.23).setScale(2, RoundingMode.HALF_EVEN);
+ final BigDecimal newAmount = new BigDecimal("15.23");
final PaymentAttemptModelDao secondAttempt = new PaymentAttemptModelDao(accountId, invoiceId, payment.getId(), newPaymentMethodId, newEffectiveDate, newAmount, currency);
paymentDao.updatePaymentWithNewAttempt(payment.getId(), secondAttempt, internalCallContext);
util/pom.xml 5(+5 -0)
diff --git a/util/pom.xml b/util/pom.xml
index f7db23e..c619b8b 100644
--- a/util/pom.xml
+++ b/util/pom.xml
@@ -180,6 +180,11 @@
<artifactId>jdbi</artifactId>
</dependency>
<dependency>
+ <groupId>org.joda</groupId>
+ <artifactId>joda-money</artifactId>
+ <version>0.9</version>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
diff --git a/util/src/main/resources/org/joda/money/MoneyDataExtension.csv b/util/src/main/resources/org/joda/money/MoneyDataExtension.csv
new file mode 100644
index 0000000..1c668d9
--- /dev/null
+++ b/util/src/main/resources/org/joda/money/MoneyDataExtension.csv
@@ -0,0 +1 @@
+BTC,-1,8
diff --git a/util/src/test/java/com/ning/billing/DBTestingHelper.java b/util/src/test/java/com/ning/billing/DBTestingHelper.java
index d24954f..00e017f 100644
--- a/util/src/test/java/com/ning/billing/DBTestingHelper.java
+++ b/util/src/test/java/com/ning/billing/DBTestingHelper.java
@@ -162,7 +162,7 @@ public class DBTestingHelper {
" account_id char(36) NOT NULL,\n" +
" invoice_id char(36) NOT NULL,\n" +
" payment_method_id char(36) NOT NULL,\n" +
- " amount numeric(10,4),\n" +
+ " amount numeric(15,9),\n" +
" currency char(3),\n" +
" effective_date datetime,\n" +
" payment_status varchar(50),\n" +