use of org.killbill.billing.invoice.model.ItemAdjInvoiceItem in project killbill by killbill.
the class TestSubscriptionItemTree method testWithWrongInitialItem.
@Test(groups = "fast")
public void testWithWrongInitialItem() throws IOException {
final LocalDate wrongStartDate = new LocalDate(2016, 9, 9);
final LocalDate correctStartDate = new LocalDate(2016, 9, 8);
final LocalDate endDate = new LocalDate(2016, 10, 8);
final BigDecimal rate = new BigDecimal("12.00");
final BigDecimal amount = rate;
final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
final InvoiceItem wrongInitialItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, wrongStartDate, endDate, amount, rate, currency);
tree.addItem(wrongInitialItem);
final InvoiceItem itemAdj = new ItemAdjInvoiceItem(wrongInitialItem, new LocalDate(2016, 10, 2), amount.negate(), currency);
tree.addItem(itemAdj);
final InvoiceItem correctInitialItem = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, correctStartDate, endDate, amount, rate, currency);
tree.flatten(true);
tree.mergeProposedItem(correctInitialItem);
tree.buildForMerge();
final InvoiceItem expected = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, productName, planName, phaseName, null, correctStartDate, wrongStartDate, new BigDecimal("0.40"), rate, currency);
final List<InvoiceItem> expectedResult = ImmutableList.<InvoiceItem>of(expected);
verifyResult(tree.getView(), expectedResult);
}
Aggregations