org.joda.time.LocalDate

Here are the examples of the java api class org.joda.time.LocalDate taken from open source projects.

1. RangeUnitTest#testGetFirstWeekMinDate()

View license
@Test
public void testGetFirstWeekMinDate() throws Exception {
    LocalDate today = LocalDate.now();
    LocalDate minDate = today.minusMonths(2);
    LocalDate date = minDate.minusWeeks(1);
    RangeUnit unit = new Week(date, today, minDate, today);
    LocalDate firstMonday = minDate.withDayOfMonth(1).withDayOfWeek(DateTimeConstants.MONDAY);
    int week = Days.daysBetween(firstMonday, minDate).dividedBy(DateTimeConstants.DAYS_PER_WEEK).getDays();
    assertEquals(week, unit.getFirstWeek(date));
}

2. InterestRateChartFields#isOverlapping()

View license
public boolean isOverlapping(InterestRateChartFields that) {
    final LocalDate thisFromDate = this.getFromDateAsLocalDate();
    LocalDate thisEndDate = this.getEndDateAsLocalDate();
    thisEndDate = thisEndDate == null ? DateUtils.getLocalDateOfTenant() : thisEndDate;
    final LocalDate thatFromDate = that.getFromDateAsLocalDate();
    LocalDate thatEndDate = that.getEndDateAsLocalDate();
    thatEndDate = thatEndDate == null ? DateUtils.getLocalDateOfTenant() : thatEndDate;
    final LocalDateInterval thisInterval = LocalDateInterval.create(thisFromDate, thisEndDate);
    final LocalDateInterval thatInterval = LocalDateInterval.create(thatFromDate, thatEndDate);
    if (thisInterval.containsPortionOf(thatInterval) || thatInterval.containsPortionOf(thisInterval)) {
        return true;
    }
    // no overlapping
    return false;
}

3. LoanApplicationWritePlatformServiceJpaRepositoryImpl#validateSubmittedOnDate()

View license
private void validateSubmittedOnDate(final Loan loan) {
    final LocalDate startDate = loan.loanProduct().getStartDate();
    final LocalDate closeDate = loan.loanProduct().getCloseDate();
    final LocalDate expectedFirstRepaymentOnDate = loan.getExpectedFirstRepaymentOnDate();
    final LocalDate submittedOnDate = loan.getSubmittedOnDate();
    String defaultUserMessage = "";
    if (startDate != null && submittedOnDate.isBefore(startDate)) {
        defaultUserMessage = "submittedOnDate cannot be before the loan product startDate.";
        throw new LoanApplicationDateException("submitted.on.date.cannot.be.before.the.loan.product.start.date", defaultUserMessage, submittedOnDate.toString(), startDate.toString());
    }
    if (closeDate != null && submittedOnDate.isAfter(closeDate)) {
        defaultUserMessage = "submittedOnDate cannot be after the loan product closeDate.";
        throw new LoanApplicationDateException("submitted.on.date.cannot.be.after.the.loan.product.close.date", defaultUserMessage, submittedOnDate.toString(), closeDate.toString());
    }
    if (expectedFirstRepaymentOnDate != null && submittedOnDate.isAfter(expectedFirstRepaymentOnDate)) {
        defaultUserMessage = "submittedOnDate cannot be after the loans  expectedFirstRepaymentOnDate.";
        throw new LoanApplicationDateException("submitted.on.date.cannot.be.after.the.loan.expected.first.repayment.date", defaultUserMessage, submittedOnDate.toString(), expectedFirstRepaymentOnDate.toString());
    }
}

4. TestRecurringInArrear#testCalculateSimpleInvoiceItemWithBCDBeforeStartDay()

Project: killbill
Source File: TestRecurringInArrear.java
View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDBeforeStartDay() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = new LocalDate(2012, 8, 16);
    final LocalDate targetDate = new LocalDate(2012, 7, 16);
    final int billingCycleDayLocal = 15;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
    final LocalDate targetDate2 = new LocalDate(2012, 8, 15);
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 15));
    verifyInvoiceItems(startDate, endDate, targetDate2, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

5. TestRecurringInArrear#testCalculateSimpleInvoiceItemWithBCDEqualsStartDay()

Project: killbill
Source File: TestRecurringInArrear.java
View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDEqualsStartDay() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = new LocalDate(2012, 8, 16);
    final LocalDate targetDate = new LocalDate(2012, 7, 16);
    final int billingCycleDayLocal = 16;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 16));
    final LocalDate targetDate2 = new LocalDate(2012, 8, 16);
    verifyInvoiceItems(startDate, endDate, targetDate2, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

6. TestRecurringInArrear#testCalculateSimpleInvoiceItemWithBCDAfterStartDay()

Project: killbill
Source File: TestRecurringInArrear.java
View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDAfterStartDay() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = new LocalDate(2012, 8, 16);
    final LocalDate targetDate = new LocalDate(2012, 7, 16);
    final int billingCycleDayLocal = 17;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
    final LocalDate targetDate2 = new LocalDate(2012, 7, 17);
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 7, 17));
    verifyInvoiceItems(startDate, endDate, targetDate2, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

7. AvailabilityTimeLineTest#addingAnIntervalThatJoinsTwoInvalidIntervals()

View license
@Test
public void addingAnIntervalThatJoinsTwoInvalidIntervals() {
    AvailabilityTimeLine timeLine = AvailabilityTimeLine.allValid();
    LocalDate intervalStart = contemporaryExample.minusDays(10);
    LocalDate intervalEnd = contemporaryExample.plusDays(5);
    timeLine.invalidAt(intervalStart, intervalEnd);
    timeLine.invalidAt(intervalStart.minusDays(20), intervalStart.minusDays(10));
    timeLine.invalidAt(intervalStart.minusDays(10), intervalStart);
    LocalDate current = intervalStart.minusDays(20);
    while (current.isBefore(intervalEnd)) {
        assertFalse(timeLine.isValid(current));
        current = current.plusDays(1);
    }
}

8. CalendarManagerTest#testInit()

View license
@Test
public void testInit() throws Exception {
    LocalDate now = LocalDate.now();
    LocalDate min = now.minusDays(3);
    LocalDate max = min.plusMonths(3);
    mCalendarManager.init(now, min, max);
    assertEquals(now, mCalendarManager.getSelectedDay());
    assertEquals(min, mCalendarManager.getMinDate());
    assertEquals(max, mCalendarManager.getMaxDate());
    assertEquals(now.withDayOfMonth(1), mCalendarManager.getActiveMonth());
    CalendarUnit unit = new Month(now, now, min, max);
    unit.setSelected(true);
    assertEquals(unit, mCalendarManager.getUnits());
}

9. CalendarManagerTest#testInitWeek()

View license
@Test
public void testInitWeek() throws Exception {
    LocalDate now = LocalDate.now();
    LocalDate min = now.minusDays(3);
    LocalDate max = min.plusMonths(3);
    CalendarManager manager = new CalendarManager(now, CalendarManager.State.WEEK, min, max);
    CalendarUnit unit = new Week(now, now, min, max);
    unit.setSelected(true);
    assertEquals(unit, manager.getUnits());
}

10. WeekTest#testNextFalse()

View license
@Test
public void testNextFalse() throws Exception {
    LocalDate today = LocalDate.parse("2014-08-01");
    LocalDate start = LocalDate.parse("2014-07-28");
    LocalDate end = LocalDate.parse("2014-08-3");
    Week week = new Week(today, today, today, today);
    assertFalse(week.next());
    assertEquals(start, week.getFrom());
    assertEquals(end, week.getTo());
    assertEquals(start, week.getDays().get(0).getDate());
    assertEquals(end, week.getDays().get(6).getDate());
}

11. WeekTest#testPrevFalse()

View license
@Test
public void testPrevFalse() throws Exception {
    LocalDate today = LocalDate.parse("2014-08-01");
    LocalDate start = LocalDate.parse("2014-07-28");
    LocalDate end = LocalDate.parse("2014-08-3");
    Week week = new Week(today, today, today, today);
    assertFalse(week.prev());
    assertEquals(start, week.getFrom());
    assertEquals(end, week.getTo());
    assertEquals(start, week.getDays().get(0).getDate());
    assertEquals(end, week.getDays().get(6).getDate());
}

12. Driver#run()

Project: bigtop
Source File: Driver.java
View license
public void run(String[] args) throws Exception {
    locations = new LocationReader().readData();
    parseArgs(args);
    WeatherGenerator generator = new WeatherGenerator(startDate, location, seedFactory);
    LocalDate date = startDate;
    LocalDate endDate = startDate.plusDays(simulationLength);
    List<WeatherRecord> trajectory = Lists.newArrayList();
    while (date.isBefore(endDate)) {
        WeatherRecord weather = generator.sample();
        trajectory.add(weather);
        date = weather.getDate();
    }
    writeWeather(location, trajectory);
}

13. Holiday#createNew()

Project: incubator-fineract
Source File: Holiday.java
View license
public static Holiday createNew(final Set<Office> offices, final JsonCommand command) {
    final String name = command.stringValueOfParameterNamed(HolidayApiConstants.nameParamName);
    final LocalDate fromDate = command.localDateValueOfParameterNamed(HolidayApiConstants.fromDateParamName);
    final LocalDate toDate = command.localDateValueOfParameterNamed(HolidayApiConstants.toDateParamName);
    final LocalDate repaymentsRescheduledTo = command.localDateValueOfParameterNamed(HolidayApiConstants.repaymentsRescheduledToParamName);
    final Integer status = HolidayStatusType.PENDING_FOR_ACTIVATION.getValue();
    // default it to false. Only batch job
    final boolean processed = false;
    // should update this field.
    final String description = command.stringValueOfParameterNamed(HolidayApiConstants.descriptionParamName);
    return new Holiday(name, fromDate, toDate, repaymentsRescheduledTo, status, processed, description, offices);
}

14. CalendarUtils#getNextScheduleDate()

View license
public static LocalDate getNextScheduleDate(final Calendar calendar, final LocalDate startDate) {
    final Recur recur = CalendarUtils.getICalRecur(calendar.getRecurrence());
    if (recur == null) {
        return null;
    }
    LocalDate date = startDate;
    final LocalDate seedDate = calendar.getStartDateLocalDate();
    /**
         * if (isValidRedurringDate(calendar.getRecurrence(), seedDate, date)) {
         * date = date.plusDays(1); }
         **/
    final LocalDate scheduleDate = getNextRecurringDate(recur, seedDate, date);
    return scheduleDate;
}

15. FloatingRatePeriod#toData()

View license
public FloatingRatePeriodData toData(final FloatingRateDTO floatingRateDTO) {
    BigDecimal interest = getInterestRate().add(floatingRateDTO.getInterestRateDiff());
    if (isDifferentialToBaseLendingRate()) {
        interest = interest.add(floatingRateDTO.fetchBaseRate(fetchFromDate()));
    }
    final LocalDate fromDate = new LocalDateTime(getFromDate()).toLocalDate();
    final LocalDate createdOn = new LocalDateTime(getCreatedOn()).toLocalDate();
    final LocalDate modidiedOn = new LocalDateTime(getModifiedOn()).toLocalDate();
    return new FloatingRatePeriodData(getId(), fromDate, interest, isDifferentialToBaseLendingRate(), isActive(), getCreatedBy().getUsername(), createdOn, getModifiedBy().getUsername(), modidiedOn);
}

16. Loan#possibleNextRepaymentDate()

Project: incubator-fineract
Source File: Loan.java
View license
public LocalDate possibleNextRepaymentDate() {
    LocalDate earliestUnpaidInstallmentDate = new LocalDate();
    List<LoanRepaymentScheduleInstallment> installments = getRepaymentScheduleInstallments();
    for (final LoanRepaymentScheduleInstallment installment : installments) {
        if (installment.isNotFullyPaidOff()) {
            earliestUnpaidInstallmentDate = installment.getDueDate();
            break;
        }
    }
    LocalDate lastTransactionDate = null;
    for (final LoanTransaction transaction : this.loanTransactions) {
        if (transaction.isRepayment() && transaction.isNonZero()) {
            lastTransactionDate = transaction.getTransactionDate();
        }
    }
    LocalDate possibleNextRepaymentDate = earliestUnpaidInstallmentDate;
    if (lastTransactionDate != null && lastTransactionDate.isAfter(earliestUnpaidInstallmentDate)) {
        possibleNextRepaymentDate = lastTransactionDate;
    }
    return possibleNextRepaymentDate;
}

17. RecurringDepositAccount#generateSchedule()

View license
public void generateSchedule(final PeriodFrequencyType frequency, final Integer recurringEvery, final Calendar calendar) {
    this.depositScheduleInstallments.clear();
    this.isDepositScheduleInstallmentDirty = true;
    LocalDate installmentDate = null;
    if (this.isCalendarInherited()) {
        installmentDate = CalendarUtils.getNextScheduleDate(calendar, accountSubmittedOrActivationDate());
    } else {
        installmentDate = depositStartDate();
    }
    int installmentNumber = 1;
    final LocalDate maturityDate = calcualteScheduleTillDate(frequency, recurringEvery);
    final BigDecimal depositAmount = this.recurringDetail.mandatoryRecommendedDepositAmount();
    while (maturityDate.isAfter(installmentDate)) {
        final RecurringDepositScheduleInstallment installment = RecurringDepositScheduleInstallment.installment(this, installmentNumber, installmentDate.toDate(), depositAmount);
        addDepositScheduleInstallment(installment);
        installmentDate = DepositAccountUtils.calculateNextDepositDate(installmentDate, frequency, recurringEvery);
        installmentNumber += 1;
    }
    updateDepositAmount();
}

18. ExecutionParametersTest#roundTripLocalDate()

Project: isis
Source File: ExecutionParametersTest.java
View license
@Test
public void roundTripLocalDate() throws Exception {
    // given
    final LocalDate value = LocalDate.now();
    // when
    executionParameters.setParameter("test", value);
    final LocalDate roundTripped = executionParameters.getParameterAsLocalDate("test");
    final LocalDate roundTrippedAsT = executionParameters.getParameterAsT("test", LocalDate.class);
    // then
    assertThat(roundTripped, is(value));
    assertThat(roundTrippedAsT, is(value));
}

19. TestDateUtils#testGetRelativeTimeSpanStringWithPreposition()

View license
public void testGetRelativeTimeSpanStringWithPreposition() {
    Context ctx = getInstrumentation().getContext();
    LocalDate today = LocalDate.now();
    LocalDate tomorrow = today.plusDays(1);
    LocalDate nextYear = today.plusYears(1);
    assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, today, false));
    assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, today, true));
    assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, false));
    assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrow, true));
    assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, false));
    assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYear, true));
    DateTime todayDt = DateTime.now();
    DateTime tomorrowDt = todayDt.plusDays(1);
    DateTime nextYearDt = todayDt.plusYears(1);
    assertEquals("12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, false));
    assertEquals("at 12:35", DateUtils.getRelativeTimeSpanString(ctx, todayDt, true));
    assertEquals("Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, false));
    assertEquals("on Oct 23, 1995", DateUtils.getRelativeTimeSpanString(ctx, tomorrowDt, true));
    assertEquals("10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, false));
    assertEquals("on 10/22/1996", DateUtils.getRelativeTimeSpanString(ctx, nextYearDt, true));
}

20. BillingIntervalDetail#calculateFirstBillingCycleDate()

Project: killbill
Source File: BillingIntervalDetail.java
View license
@VisibleForTesting
void calculateFirstBillingCycleDate() {
    final int lastDayOfMonth = startDate.dayOfMonth().getMaximumValue();
    final LocalDate billingCycleDate;
    if (billingCycleDay > lastDayOfMonth) {
        billingCycleDate = new LocalDate(startDate.getYear(), startDate.getMonthOfYear(), lastDayOfMonth, startDate.getChronology());
    } else {
        billingCycleDate = new LocalDate(startDate.getYear(), startDate.getMonthOfYear(), billingCycleDay, startDate.getChronology());
    }
    final int numberOfMonthsInPeriod = billingPeriod.getNumberOfMonths();
    LocalDate proposedDate = billingCycleDate;
    while (proposedDate.isBefore(startDate)) {
        proposedDate = proposedDate.plusMonths(numberOfMonthsInPeriod);
    }
    firstBillingCycleDate = alignProposedBillCycleDate(proposedDate, billingCycleDay);
}

21. InvoiceDateUtils#calculateBillingCycleDateOnOrAfter()

Project: killbill
Source File: InvoiceDateUtils.java
View license
public static LocalDate calculateBillingCycleDateOnOrAfter(final LocalDate date, final int billingCycleDayLocal) {
    final int lastDayOfMonth = date.dayOfMonth().getMaximumValue();
    final LocalDate fixedDate;
    if (billingCycleDayLocal > lastDayOfMonth) {
        fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), lastDayOfMonth, date.getChronology());
    } else {
        fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), billingCycleDayLocal, date.getChronology());
    }
    LocalDate proposedDate = fixedDate;
    while (proposedDate.isBefore(date)) {
        proposedDate = proposedDate.plusMonths(1);
    }
    return proposedDate;
}

22. ContiguousIntervalConsumableInArrear#computeNextNotificationDate()

View license
private LocalDate computeNextNotificationDate() {
    LocalDate result = null;
    final Iterator<BillingEvent> eventIt = billingEvents.iterator();
    BillingEvent nextEvent = eventIt.next();
    while (eventIt.hasNext()) {
        final BillingEvent thisEvent = nextEvent;
        nextEvent = eventIt.next();
        final LocalDate startDate = dateAndTimeZoneContext.computeLocalDateFromFixedAccountOffset(thisEvent.getEffectiveDate());
        final LocalDate endDate = dateAndTimeZoneContext.computeLocalDateFromFixedAccountOffset(nextEvent.getEffectiveDate());
        final BillingIntervalDetail bid = new BillingIntervalDetail(startDate, endDate, targetDate, thisEvent.getBillCycleDayLocal(), usage.getBillingPeriod(), BillingMode.IN_ARREAR);
        final LocalDate nextBillingCycleDate = bid.getNextBillingCycleDate();
        result = (result == null || result.compareTo(nextBillingCycleDate) < 0) ? nextBillingCycleDate : result;
    }
    final LocalDate startDate = dateAndTimeZoneContext.computeLocalDateFromFixedAccountOffset(nextEvent.getEffectiveDate());
    final BillingIntervalDetail bid = new BillingIntervalDetail(startDate, null, targetDate, nextEvent.getBillCycleDayLocal(), usage.getBillingPeriod(), BillingMode.IN_ARREAR);
    final LocalDate nextBillingCycleDate = bid.getNextBillingCycleDate();
    result = (result == null || result.compareTo(nextBillingCycleDate) < 0) ? nextBillingCycleDate : result;
    return result;
}

23. TestInvoiceDao#testAccountBalanceWithCredit()

Project: killbill
Source File: TestInvoiceDao.java
View license
@Test(groups = "slow")
public void testAccountBalanceWithCredit() throws EntityPersistenceException {
    final UUID accountId = account.getId();
    final UUID bundleId = UUID.randomUUID();
    final LocalDate targetDate1 = new LocalDate(2011, 10, 6);
    final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate1, Currency.USD);
    invoiceUtil.createInvoice(invoice1, true, context);
    final LocalDate startDate = new LocalDate(2011, 3, 1);
    final LocalDate endDate = startDate.plusMonths(1);
    final BigDecimal rate1 = new BigDecimal("17.0");
    final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate, endDate, rate1, rate1, Currency.USD);
    invoiceUtil.createInvoiceItem(item1, context);
    final CreditAdjInvoiceItem creditItem = new CreditAdjInvoiceItem(invoice1.getId(), accountId, new LocalDate(), rate1.negate(), Currency.USD);
    invoiceUtil.createInvoiceItem(creditItem, context);
    final BigDecimal balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(BigDecimal.ZERO), 0);
}

24. TestInvoiceDao#testAccountBalanceWithNoPayments()

Project: killbill
Source File: TestInvoiceDao.java
View license
@Test(groups = "slow")
public void testAccountBalanceWithNoPayments() throws EntityPersistenceException {
    final UUID accountId = account.getId();
    final UUID bundleId = UUID.randomUUID();
    final LocalDate targetDate1 = new LocalDate(2011, 10, 6);
    final Invoice invoice1 = new DefaultInvoice(accountId, clock.getUTCToday(), targetDate1, Currency.USD);
    invoiceUtil.createInvoice(invoice1, true, context);
    final LocalDate startDate = new LocalDate(2011, 3, 1);
    final LocalDate endDate = startDate.plusMonths(1);
    final BigDecimal rate1 = new BigDecimal("17.0");
    final BigDecimal rate2 = new BigDecimal("42.0");
    final RecurringInvoiceItem item1 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase A", startDate, endDate, rate1, rate1, Currency.USD);
    invoiceUtil.createInvoiceItem(item1, context);
    final RecurringInvoiceItem item2 = new RecurringInvoiceItem(invoice1.getId(), accountId, bundleId, UUID.randomUUID(), "test plan", "test phase B", startDate, endDate, rate2, rate2, Currency.USD);
    invoiceUtil.createInvoiceItem(item2, context);
    final BigDecimal balance = invoiceDao.getAccountBalance(accountId, context);
    assertEquals(balance.compareTo(rate1.add(rate2)), 0);
}

25. TestInArrearBillingIntervalDetail#testScenarioBCDAfterStart2()

View license
/*
     *                       TD
     * Start    End          BCD
     * |---------|------------|-------
     *
     */
@Test(groups = "fast")
public void testScenarioBCDAfterStart2() throws Exception {
    final LocalDate start = new LocalDate("2012-01-16");
    final LocalDate end = new LocalDate("2012-01-19");
    final LocalDate targetDate = new LocalDate("2012-01-25");
    final int bcd = 25;
    final BillingIntervalDetail billingIntervalDetail = new BillingIntervalDetail(start, end, targetDate, bcd, BillingPeriod.MONTHLY, BillingMode.IN_ARREAR);
    Assert.assertTrue(billingIntervalDetail.hasSomethingToBill());
    Assert.assertEquals(billingIntervalDetail.getFirstBillingCycleDate(), new LocalDate("2012-01-25"));
    Assert.assertEquals(billingIntervalDetail.getEffectiveEndDate(), end);
    // STEPH maybe we should change because we actually don't want a notification
    Assert.assertEquals(billingIntervalDetail.getNextBillingCycleDate(), new LocalDate("2012-01-25"));
}

26. TestInArrearBillingIntervalDetail#testScenarioEndDateBetweenPeriod1()

View license
/*
     *
     * Start   BCD   end   TD  next BCD
     * |-------|------|----|------|---
     *
     */
@Test(groups = "fast")
public void testScenarioEndDateBetweenPeriod1() throws Exception {
    final LocalDate start = new LocalDate("2012-01-16");
    final LocalDate end = new LocalDate("2012-01-20");
    final LocalDate targetDate = new LocalDate("2012-01-25");
    final int bcd = 18;
    final BillingIntervalDetail billingIntervalDetail = new BillingIntervalDetail(start, end, targetDate, bcd, BillingPeriod.MONTHLY, BillingMode.IN_ARREAR);
    Assert.assertTrue(billingIntervalDetail.hasSomethingToBill());
    Assert.assertEquals(billingIntervalDetail.getFirstBillingCycleDate(), new LocalDate("2012-01-18"));
    Assert.assertEquals(billingIntervalDetail.getEffectiveEndDate(), new LocalDate("2012-01-20"));
    Assert.assertEquals(billingIntervalDetail.getNextBillingCycleDate(), new LocalDate("2012-02-18"));
}

27. TestInArrearBillingIntervalDetail#testScenarioEndDateBetweenPeriod3()

View license
/*
     *
     * Start   BCD       TD    end   next BCD
     * |-------|----------|----|------|---
     *
     */
@Test(groups = "fast")
public void testScenarioEndDateBetweenPeriod3() throws Exception {
    final LocalDate start = new LocalDate("2012-01-16");
    final LocalDate end = new LocalDate("2012-01-28");
    final LocalDate targetDate = new LocalDate("2012-01-25");
    final int bcd = 18;
    final BillingIntervalDetail billingIntervalDetail = new BillingIntervalDetail(start, end, targetDate, bcd, BillingPeriod.MONTHLY, BillingMode.IN_ARREAR);
    Assert.assertTrue(billingIntervalDetail.hasSomethingToBill());
    Assert.assertEquals(billingIntervalDetail.getFirstBillingCycleDate(), new LocalDate("2012-01-18"));
    Assert.assertEquals(billingIntervalDetail.getEffectiveEndDate(), new LocalDate("2012-01-18"));
    Assert.assertEquals(billingIntervalDetail.getNextBillingCycleDate(), new LocalDate("2012-02-18"));
}

28. TestInArrearBillingIntervalDetail#testScenarioTargetDateOnNextBCD2()

View license
/*
     *                              TD
     * Start   BCD          end    next BCD
     * |-------|-------------|-------|---
     *
     */
@Test(groups = "fast")
public void testScenarioTargetDateOnNextBCD2() throws Exception {
    final LocalDate start = new LocalDate("2012-01-16");
    final LocalDate end = new LocalDate("2012-02-16");
    final LocalDate targetDate = new LocalDate("2012-02-18");
    final int bcd = 18;
    final BillingIntervalDetail billingIntervalDetail = new BillingIntervalDetail(start, end, targetDate, bcd, BillingPeriod.MONTHLY, BillingMode.IN_ARREAR);
    Assert.assertTrue(billingIntervalDetail.hasSomethingToBill());
    Assert.assertEquals(billingIntervalDetail.getFirstBillingCycleDate(), new LocalDate("2012-01-18"));
    Assert.assertEquals(billingIntervalDetail.getEffectiveEndDate(), new LocalDate("2012-02-16"));
    Assert.assertEquals(billingIntervalDetail.getNextBillingCycleDate(), new LocalDate("2012-02-18"));
}

29. TestRecurringInAdvance#testCalculateSimpleInvoiceItemWithNoEndDate()

View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithNoEndDate() throws Exception {
    final LocalDate startDate = new LocalDate(new DateTime("2012-07-17T02:25:33.000Z", DateTimeZone.UTC), TIMEZONE);
    final LocalDate endDate = null;
    final LocalDate targetDate = new LocalDate(2012, 7, 16);
    final int billingCycleDayLocal = 15;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 15));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

30. TestRecurringInAdvance#testCalculateSimpleInvoiceItemWithBCDBeforeStartDay()

View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDBeforeStartDay() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = new LocalDate(2012, 8, 16);
    final LocalDate targetDate = new LocalDate(2012, 7, 16);
    final int billingCycleDayLocal = 15;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 15));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

31. TestRecurringInAdvance#testCalculateSimpleInvoiceItemWithBCDEqualsStartDay()

View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDEqualsStartDay() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = new LocalDate(2012, 8, 16);
    final LocalDate targetDate = new LocalDate(2012, 7, 16);
    final int billingCycleDayLocal = 16;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 16));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

32. TestRecurringInAdvance#testCalculateSimpleInvoiceItemWithBCDAfterStartDay()

View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDAfterStartDay() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = new LocalDate(2012, 8, 16);
    final LocalDate targetDate = new LocalDate(2012, 7, 16);
    final int billingCycleDayLocal = 17;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 7, 17));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

33. TestRecurringInAdvance#testCalculateSimpleInvoiceItemWithBCDBeforeStartDayWithTargetDateIn3Months()

View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDBeforeStartDayWithTargetDateIn3Months() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = null;
    final LocalDate targetDate = new LocalDate(2012, 10, 16);
    final int billingCycleDayLocal = 15;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 15));
    expectedDates.put(new LocalDate(2012, 8, 15), new LocalDate(2012, 9, 15));
    expectedDates.put(new LocalDate(2012, 9, 15), new LocalDate(2012, 10, 15));
    expectedDates.put(new LocalDate(2012, 10, 15), new LocalDate(2012, 11, 15));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

34. TestRecurringInAdvance#testCalculateSimpleInvoiceItemWithBCDEqualsStartDayWithTargetDateIn3Months()

View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDEqualsStartDayWithTargetDateIn3Months() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = null;
    final LocalDate targetDate = new LocalDate(2012, 10, 16);
    final int billingCycleDayLocal = 16;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 16));
    expectedDates.put(new LocalDate(2012, 8, 16), new LocalDate(2012, 9, 16));
    expectedDates.put(new LocalDate(2012, 9, 16), new LocalDate(2012, 10, 16));
    expectedDates.put(new LocalDate(2012, 10, 16), new LocalDate(2012, 11, 16));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

35. TestRecurringInAdvance#testCalculateSimpleInvoiceItemWithBCDAfterStartDayWithTargetDateIn3Months()

View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDAfterStartDayWithTargetDateIn3Months() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = null;
    final LocalDate targetDate = new LocalDate(2012, 10, 16);
    final int billingCycleDayLocal = 17;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 7, 17));
    expectedDates.put(new LocalDate(2012, 7, 17), new LocalDate(2012, 8, 17));
    expectedDates.put(new LocalDate(2012, 8, 17), new LocalDate(2012, 9, 17));
    expectedDates.put(new LocalDate(2012, 9, 17), new LocalDate(2012, 10, 17));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

36. TestRecurringInArrear#testCalculateSimpleInvoiceItemWithBCDBeforeStartDayWithTargetDateIn3Months()

Project: killbill
Source File: TestRecurringInArrear.java
View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDBeforeStartDayWithTargetDateIn3Months() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = null;
    final LocalDate targetDate = new LocalDate(2012, 10, 16);
    final int billingCycleDayLocal = 15;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 15));
    expectedDates.put(new LocalDate(2012, 8, 15), new LocalDate(2012, 9, 15));
    expectedDates.put(new LocalDate(2012, 9, 15), new LocalDate(2012, 10, 15));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

37. TestRecurringInArrear#testCalculateSimpleInvoiceItemWithBCDEqualsStartDayWithTargetDateIn3Months()

Project: killbill
Source File: TestRecurringInArrear.java
View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDEqualsStartDayWithTargetDateIn3Months() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = null;
    final LocalDate targetDate = new LocalDate(2012, 10, 16);
    final int billingCycleDayLocal = 16;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 8, 16));
    expectedDates.put(new LocalDate(2012, 8, 16), new LocalDate(2012, 9, 16));
    expectedDates.put(new LocalDate(2012, 9, 16), new LocalDate(2012, 10, 16));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

38. TestRecurringInArrear#testCalculateSimpleInvoiceItemWithBCDAfterStartDayWithTargetDateIn3Months()

Project: killbill
Source File: TestRecurringInArrear.java
View license
@Test(groups = "fast")
public void testCalculateSimpleInvoiceItemWithBCDAfterStartDayWithTargetDateIn3Months() throws Exception {
    final LocalDate startDate = new LocalDate(2012, 7, 16);
    final LocalDate endDate = null;
    final LocalDate targetDate = new LocalDate(2012, 10, 16);
    final int billingCycleDayLocal = 17;
    final LinkedHashMap<LocalDate, LocalDate> expectedDates = new LinkedHashMap<LocalDate, LocalDate>();
    expectedDates.put(new LocalDate(2012, 7, 16), new LocalDate(2012, 7, 17));
    expectedDates.put(new LocalDate(2012, 7, 17), new LocalDate(2012, 8, 17));
    expectedDates.put(new LocalDate(2012, 8, 17), new LocalDate(2012, 9, 17));
    verifyInvoiceItems(startDate, endDate, targetDate, billingCycleDayLocal, BILLING_PERIOD, expectedDates);
}

39. TestDoubleProRation#testDoubleProRation_TargetDateInFullBillingPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInFullBillingPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 22);
    final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

40. TestDoubleProRation#testDoubleProRation_TargetDateOnSecondBillingCycleDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnSecondBillingCycleDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2012, 1, 15);
    final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
    BigDecimal expectedValue;
    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, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

41. TestDoubleProRation#testDoubleProRation_TargetDateInSecondProRationPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2012, 1, 17);
    final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
    BigDecimal expectedValue;
    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, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

42. TestDoubleProRation#testDoubleProRation_TargetDateOnEndDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnEndDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2012, 1, 27);
    final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
    BigDecimal expectedValue;
    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, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

43. TestDoubleProRation#testDoubleProRation_TargetDateAfterEndDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateAfterEndDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2012, 3, 7);
    final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
    BigDecimal expectedValue;
    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, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

44. TestDoubleProRation#testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2012, 2, 26);
    final LocalDate endDate = invoiceUtil.buildDate(2013, 4, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(TWO);
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

45. TestProRation#testSinglePlanDoubleProRation()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testSinglePlanDoubleProRation() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 10);
    final LocalDate endDate = invoiceUtil.buildDate(2012, 3, 4);
    final LocalDate targetDate = invoiceUtil.buildDate(2012, 4, 5);
    // SEVEN is number of days between startDate and expected first billing cycle date (2011, 1, 17);
    // FORTY_SEVEN is number of days between the second billing cycle date (2012, 1, 17) and the end date (2012, 3, 4);
    // 2011 has 365 days but 2012 has 366 days
    final BigDecimal expectedValue = ONE.add(SEVEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, KillBillMoney.ROUNDING_METHOD)).add(FORTY_SEVEN.divide(THREE_HUNDRED_AND_SIXTY_SIX, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 17, expectedValue);
}

46. TestDoubleProRation#testDoubleProRation_TargetDateInFullBillingPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInFullBillingPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 22);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

47. TestDoubleProRation#testDoubleProRation_TargetDateOnSecondBillingCycleDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnSecondBillingCycleDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 27);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

48. TestDoubleProRation#testDoubleProRation_TargetDateInSecondProRationPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 26);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

49. TestDoubleProRation#testDoubleProRation_TargetDateOnEndDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnEndDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 27);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

50. TestDoubleProRation#testDoubleProRation_TargetDateAfterEndDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateAfterEndDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 7);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 2, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(TWELVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

51. TestDoubleProRation#testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 2, 26);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(TWO);
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

52. TestProRation#testSinglePlan_ChangeBCDTo31()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testSinglePlan_ChangeBCDTo31() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 1);
    final LocalDate planChangeDate = invoiceUtil.buildDate(2011, 2, 14);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 1);
    BigDecimal expectedValue;
    expectedValue = THIRTEEN.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
    expectedValue = ONE.add(FOURTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 31, expectedValue);
}

53. TestProRation#testSinglePlan_ChangeBCD()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testSinglePlan_ChangeBCD() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 1);
    final LocalDate planChangeDate = invoiceUtil.buildDate(2011, 2, 14);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 1);
    BigDecimal expectedValue;
    expectedValue = THIRTEEN.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
    expectedValue = ONE.add(THIRTEEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 27, expectedValue);
}

54. TestProRation#testPlanChange_BeforeBillingDay()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testPlanChange_BeforeBillingDay() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 7);
    final LocalDate changeDate = invoiceUtil.buildDate(2011, 2, 15);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 21);
    final BigDecimal expectedValue;
    expectedValue = EIGHT.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, expectedValue);
    testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, THREE);
}

55. TestProRation#testPlanChange_OnBillingDay()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testPlanChange_OnBillingDay() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 7);
    final LocalDate changeDate = invoiceUtil.buildDate(2011, 3, 7);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 21);
    testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, ONE);
    final BigDecimal expectedValue;
    expectedValue = EIGHT.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD).add(TWO);
    testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}

56. TestProRation#testPlanChange_AfterBillingDay()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testPlanChange_AfterBillingDay() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 7);
    final LocalDate changeDate = invoiceUtil.buildDate(2011, 3, 10);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 21);
    BigDecimal expectedValue;
    expectedValue = BigDecimal.ONE.add(THREE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, expectedValue);
    expectedValue = FIVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD).add(TWO);
    testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}

57. TestProRation#testPlanChange_DoubleProRation()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testPlanChange_DoubleProRation() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 31);
    final LocalDate planChangeDate = invoiceUtil.buildDate(2011, 3, 10);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 21);
    BigDecimal expectedValue;
    expectedValue = SEVEN.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(THREE.divide(THIRTY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 7, expectedValue);
    expectedValue = FIVE.divide(TWENTY_EIGHT, KillBillMoney.ROUNDING_METHOD).add(TWO);
    testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, expectedValue);
}

58. TestDoubleProRation#testDoubleProRation_TargetDateInFullBillingPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInFullBillingPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 1, 22);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

59. TestDoubleProRation#testDoubleProRation_TargetDateOnSecondBillingCycleDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnSecondBillingCycleDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 15);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

60. TestDoubleProRation#testDoubleProRation_TargetDateInSecondProRationPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 26);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

61. TestDoubleProRation#testDoubleProRation_TargetDateOnEndDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateOnEndDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 4, 27);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

62. TestDoubleProRation#testDoubleProRation_TargetDateAfterEndDate()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRation_TargetDateAfterEndDate() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 5, 7);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 4, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(ONE);
    expectedValue = expectedValue.add(TWELVE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

63. TestDoubleProRation#testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod()

Project: killbill
Source File: TestDoubleProRation.java
View license
@Test(groups = "fast")
public void testDoubleProRationWithMultiplePeriods_TargetDateInSecondFullBillingPeriod() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 6, 26);
    final LocalDate endDate = invoiceUtil.buildDate(2011, 8, 27);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD);
    expectedValue = expectedValue.add(TWO);
    testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

64. TestProRation#testSinglePlan_WithPhaseChange()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testSinglePlan_WithPhaseChange() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 10);
    final LocalDate phaseChangeDate = invoiceUtil.buildDate(2011, 2, 24);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 6);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, phaseChangeDate, targetDate, 10, expectedValue);
    // 75 is number of days between phaseChangeDate and next billing cycle date (2011, 5, 10)
    // 89 is total number of days between the next and previous billing period  (2011, 2, 10) -> (2011, 5, 10)
    expectedValue = SEVENTY_FIVE.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 10, expectedValue);
}

65. TestProRation#testSinglePlan_WithPhaseChange_OnBillCycleDay()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testSinglePlan_WithPhaseChange_OnBillCycleDay() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 3);
    final LocalDate phaseChangeDate = invoiceUtil.buildDate(2011, 2, 17);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 5, 3);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, phaseChangeDate, targetDate, 3, expectedValue);
    expectedValue = ONE.add(SEVENTY_FIVE.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, expectedValue);
}

66. TestProRation#testSinglePlan_WithPhaseChange_AfterBillCycleDay()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testSinglePlan_WithPhaseChange_AfterBillCycleDay() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 3);
    final LocalDate phaseChangeDate = invoiceUtil.buildDate(2011, 2, 17);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 5, 4);
    BigDecimal expectedValue;
    expectedValue = FOURTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, phaseChangeDate, targetDate, 3, expectedValue);
    expectedValue = SEVENTY_FIVE.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD).add(ONE);
    testCalculateNumberOfBillingCycles(phaseChangeDate, targetDate, 3, expectedValue);
}

67. TestProRation#testSinglePlan_ChangeBCDTo31()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testSinglePlan_ChangeBCDTo31() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 1);
    final LocalDate planChangeDate = invoiceUtil.buildDate(2011, 2, 14);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 3, 1);
    BigDecimal expectedValue;
    expectedValue = THIRTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
    expectedValue = ONE.add(FOURTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 31, expectedValue);
}

68. TestProRation#testSinglePlan_ChangeBCD()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testSinglePlan_ChangeBCD() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 1);
    final LocalDate planChangeDate = invoiceUtil.buildDate(2011, 2, 14);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 5, 1);
    BigDecimal expectedValue;
    expectedValue = THIRTEEN.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 1, expectedValue);
    expectedValue = ONE.add(THIRTEEN.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 27, expectedValue);
}

69. TestProRation#testPlanChange_BeforeBillingDay()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testPlanChange_BeforeBillingDay() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 7);
    final LocalDate changeDate = invoiceUtil.buildDate(2011, 2, 15);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 9, 21);
    final BigDecimal expectedValue;
    expectedValue = EIGHT.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD);
    testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, expectedValue);
    testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, THREE);
}

70. TestProRation#testPlanChange_OnBillingDay()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testPlanChange_OnBillingDay() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 7);
    final LocalDate changeDate = invoiceUtil.buildDate(2011, 5, 7);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 7, 21);
    testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, ONE);
    final BigDecimal expectedValue;
    expectedValue = EIGHT.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD).add(ONE);
    testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}

71. TestProRation#testPlanChange_AfterBillingDay()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testPlanChange_AfterBillingDay() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 2, 7);
    final LocalDate changeDate = invoiceUtil.buildDate(2011, 5, 10);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 9, 21);
    BigDecimal expectedValue;
    expectedValue = ONE.add(THREE.divide(NINETY_TWO, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, changeDate, targetDate, 7, expectedValue);
    expectedValue = FIVE.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD).add(TWO);
    testCalculateNumberOfBillingCycles(changeDate, targetDate, 15, expectedValue);
}

72. TestProRation#testPlanChange_DoubleProRation()

Project: killbill
Source File: TestProRation.java
View license
@Test(groups = "fast")
public void testPlanChange_DoubleProRation() throws InvalidDateSequenceException {
    final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 31);
    final LocalDate planChangeDate = invoiceUtil.buildDate(2011, 5, 10);
    final LocalDate targetDate = invoiceUtil.buildDate(2011, 5, 21);
    BigDecimal expectedValue;
    // startDate, 2011, 4, 7 -> 66 days out of 2011, 1, 7, 2011, 4, 7 -> 90
    expectedValue = SIXTY_SIX.divide(NINETY, KillBillMoney.ROUNDING_METHOD);
    // 2011, 1, 7, planChangeDate-> 33 days out of 2011, 4, 7, 2011, 7, 7 -> 89
    expectedValue = expectedValue.add(THIRTY_THREE.divide(NINETY_ONE, KillBillMoney.ROUNDING_METHOD));
    testCalculateNumberOfBillingCycles(startDate, planChangeDate, targetDate, 7, expectedValue);
    expectedValue = FIVE.divide(EIGHTY_NINE, KillBillMoney.ROUNDING_METHOD).add(ONE);
    testCalculateNumberOfBillingCycles(planChangeDate, targetDate, 15, expectedValue);
}

73. TestSubscriptionItemTree#testMergeCancellationWithInitialRepair()

View license
@Test(groups = "fast")
public void testMergeCancellationWithInitialRepair() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate blockDate = new LocalDate(2014, 1, 25);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final BigDecimal monthlyRate1 = new BigDecimal("12.00");
    final BigDecimal monthlyAmount1 = monthlyRate1;
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount1, monthlyRate1, currency);
    tree.addItem(monthly1);
    tree.flatten(true);
    final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, blockDate, endDate, monthlyAmount1, monthlyRate1, currency);
    tree.mergeProposedItem(proposed1);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, startDate, blockDate, new BigDecimal("-9.29"), currency, monthly1.getId());
    expectedResult.add(repair);
    verifyResult(tree.getView(), expectedResult);
}

74. TestSubscriptionItemTree#testMergeCancellationWithFinalRepair()

View license
@Test(groups = "fast")
public void testMergeCancellationWithFinalRepair() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate cancelDate = new LocalDate(2014, 1, 25);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final BigDecimal monthlyRate1 = new BigDecimal("12.00");
    final BigDecimal monthlyAmount1 = monthlyRate1;
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    final InvoiceItem monthly1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount1, monthlyRate1, currency);
    tree.addItem(monthly1);
    tree.flatten(true);
    final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, cancelDate, monthlyAmount1, monthlyRate1, currency);
    tree.mergeProposedItem(proposed1);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    final InvoiceItem repair = new RepairAdjInvoiceItem(invoiceId, accountId, cancelDate, endDate, new BigDecimal("-2.71"), currency, monthly1.getId());
    expectedResult.add(repair);
    verifyResult(tree.getView(), expectedResult);
}

75. TestSubscriptionItemTree#testMaxedOutProRation()

View license
@Test(groups = "fast", description = "https://github.com/killbill/killbill/issues/286")
public void testMaxedOutProRation() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate cancelDate = new LocalDate(2014, 1, 25);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final BigDecimal monthlyRate1 = new BigDecimal("12.00");
    final BigDecimal monthlyAmount1 = monthlyRate1;
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    final InvoiceItem existing1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount1, monthlyRate1, currency);
    tree.addItem(existing1);
    // Fully item adjust the recurring item
    final InvoiceItem existingItemAdj1 = new ItemAdjInvoiceItem(existing1, startDate, monthlyRate1.negate(), currency);
    tree.addItem(existingItemAdj1);
    tree.flatten(true);
    final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, cancelDate, monthlyAmount1, monthlyRate1, currency);
    tree.mergeProposedItem(proposed1);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    verifyResult(tree.getView(), expectedResult);
}

76. TestRawUsageOptimizer#testWithOneMonthlyUsageSectionTooFewItems()

Project: killbill
Source File: TestRawUsageOptimizer.java
View license
@Test(groups = "fast")
public void testWithOneMonthlyUsageSectionTooFewItems() {
    final LocalDate firstEventStartDate = new LocalDate(2014, 03, 15);
    final List<InvoiceItem> invoiceItems = new ArrayList<InvoiceItem>();
    invoiceItems.add(createUsageItem(firstEventStartDate));
    final LocalDate targetDate = invoiceItems.get(invoiceItems.size() - 1).getEndDate();
    final Map<String, Usage> knownUsage = new HashMap<String, Usage>();
    final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 1000, BigDecimal.ONE);
    final DefaultTier tier = createDefaultTier(block);
    final DefaultUsage usage = createDefaultUsage(usageName, BillingPeriod.MONTHLY, tier);
    knownUsage.put(usageName, usage);
    final LocalDate result = rawUsageOptimizer.getOptimizedRawUsageStartDate(firstEventStartDate, targetDate, invoiceItems, knownUsage);
    // The largest endDate for ii is 2014-04-15, and by default org.killbill.invoice.readMaxRawUsagePreviousPeriod == 2 => targetDate =>  2014-02-15,
    // so we default to firstEventStartDate = 2014-03-15
    Assert.assertEquals(result.compareTo(firstEventStartDate), 0);
}

77. TestRawUsageOptimizer#testWithOneMonthlyUsageSectionAndEnoughUsageItems()

Project: killbill
Source File: TestRawUsageOptimizer.java
View license
@Test(groups = "fast")
public void testWithOneMonthlyUsageSectionAndEnoughUsageItems() {
    final LocalDate firstEventStartDate = new LocalDate(2014, 03, 15);
    final List<InvoiceItem> invoiceItems = new ArrayList<InvoiceItem>();
    for (int i = 0; i < 5; i++) {
        invoiceItems.add(createUsageItem(firstEventStartDate.plusMonths(i)));
    }
    final LocalDate targetDate = invoiceItems.get(invoiceItems.size() - 1).getEndDate();
    final Map<String, Usage> knownUsage = new HashMap<String, Usage>();
    final DefaultTieredBlock block = createDefaultTieredBlock("unit", 100, 1000, BigDecimal.ONE);
    final DefaultTier tier = createDefaultTier(block);
    final DefaultUsage usage = createDefaultUsage(usageName, BillingPeriod.MONTHLY, tier);
    knownUsage.put(usageName, usage);
    final LocalDate result = rawUsageOptimizer.getOptimizedRawUsageStartDate(firstEventStartDate, targetDate, invoiceItems, knownUsage);
    // The largest endDate for ii is 2014-08-15, and by default org.killbill.invoice.readMaxRawUsagePreviousPeriod == 2 => targetDate =>  2014-06-15
    Assert.assertEquals(result.compareTo(new LocalDate(2014, 06, 15)), 0, "112 got " + result);
}

78. TimeTrackerState#createDetails()

Project: libreplan
Source File: TimeTrackerState.java
View license
private Collection<DetailItem> createDetails(Interval interval, Iterator<LocalDate> datesGenerator, IDetailItemCreator detailItemCreator) {
    LocalDate current = interval.getStart();
    LocalDate end = interval.getFinish();
    List<DetailItem> result = new ArrayList<DetailItem>();
    while (current.isBefore(end)) {
        result.add(detailItemCreator.create(current.toDateTimeAtStartOfDay()));
        assert datesGenerator.hasNext();
        current = datesGenerator.next();
    }
    return result;
}

79. SigmoidFunction#daysWithAllocatedHours()

Project: libreplan
Source File: SigmoidFunction.java
View license
private List<BigDecimal> daysWithAllocatedHours(ResourceAllocation<?> resourceAllocation) {
    List<BigDecimal> result = new ArrayList<BigDecimal>();
    LocalDate day = new LocalDate(resourceAllocation.getStartDate());
    final LocalDate end = resourceAllocation.getEndDate();
    while (day.isBefore(end)) {
        int hoursAllocated = resourceAllocation.getAssignedHours(day, day.plusDays(1));
        if (hoursAllocated != 0) {
            result.add(new BigDecimal(hoursAllocated));
        }
        day = day.plusDays(1);
    }
    return result;
}

80. DerivedAllocationTest#theAssignmentsCanBeResetOnAnInterval()

View license
@Test
public void theAssignmentsCanBeResetOnAnInterval() {
    givenADerivedAllocation();
    LocalDate start = new LocalDate(2008, 12, 1);
    givenDayAssignments(start, worker, 8, 8, 8, 8);
    derivedAllocation.resetAssignmentsTo(dayAssignments);
    final LocalDate startInterval = start.plusDays(2);
    final LocalDate finishInterval = start.plusDays(4);
    DerivedDayAssignment newAssignment = DerivedDayAssignment.create(startInterval, EffortDuration.hours(3), worker, derivedAllocation);
    derivedAllocation.resetAssignmentsTo(startInterval, finishInterval, Arrays.asList(newAssignment));
    assertThat(derivedAllocation.getAssignments(), compareValuesExceptParent(dayAssignments.get(0), dayAssignments.get(1), newAssignment));
}

81. SendEmailOnTimesheetDataMissing#getResourceCapcity()

View license
private EffortDuration getResourceCapcity(Resource resource, LocalDate date, PersonalTimesheetsPeriodicityEnum periodicity) {
    LocalDate start = periodicity.getStart(date);
    LocalDate end = periodicity.getEnd(date);
    EffortDuration capacity = EffortDuration.zero();
    for (LocalDate day = start; day.compareTo(end) <= 0; day = day.plusDays(1)) {
        capacity = capacity.plus(resource.getCalendar().getCapacityOn(IntraDayDate.PartialDay.wholeDay(day)));
    }
    return capacity;
}

82. ManualAllocationController#getValidDayInGap()

View license
/**
     * Checks if date is a valid day within gap. A day is valid within a gap if
     * it is included between gap.startTime and the last day from which is
     * possible to start doing an allocation (endAllocationDate)
     *
     * If date is valid, returns DateAndHour in gap associated with that date
     *
     * @param date
     * @param gap
     * @return
     */
private DateAndHour getValidDayInGap(LocalDate date, Gap gap) {
    final DateAndHour endAllocationDate = endAllocationDates.get(gap);
    final LocalDate start = gap.getStartTime().getDate();
    final LocalDate end = endAllocationDate != null ? endAllocationDate.getDate() : null;
    if (start.equals(date)) {
        return gap.getStartTime();
    }
    if (end != null && end.equals(date)) {
        return endAllocationDate;
    }
    if ((start.compareTo(date) <= 0 && (end == null || end.compareTo(date) >= 0))) {
        return new DateAndHour(date, 0);
    }
    return null;
}

83. PersonalTimesheetsAreaModel#getResourceCapcity()

View license
private EffortDuration getResourceCapcity(Resource resource, LocalDate date, PersonalTimesheetsPeriodicityEnum periodicity) {
    LocalDate start = periodicity.getStart(date);
    LocalDate end = periodicity.getEnd(date);
    EffortDuration capacity = EffortDuration.zero();
    for (LocalDate day = start; day.compareTo(end) <= 0; day = day.plusDays(1)) {
        capacity = capacity.plus(resource.getCalendar().getCapacityOn(PartialDay.wholeDay(day)));
    }
    return capacity;
}

84. BusinessDateTimeUtilsTest#testPlusDaysWithNegativeValues()

View license
@Test
public void testPlusDaysWithNegativeValues() {
    // Friday
    LocalDate date = new LocalDate(2015, 8, 28);
    LocalDate result = BusinessDayTimeUtils.plusDays(date, -1);
    Assert.assertEquals(0, result.compareTo(new LocalDate(2015, 8, 27)));
    result = BusinessDayTimeUtils.plusDays(date, -5);
    Assert.assertEquals(0, result.compareTo(new LocalDate(2015, 8, 21)));
    //Monday
    date = new LocalDate(2015, 8, 24);
    result = BusinessDayTimeUtils.plusDays(date, -1);
    Assert.assertEquals(0, result.compareTo(new LocalDate(2015, 8, 21)));
}

85. Week#isDayEnabled()

View license
private boolean isDayEnabled(@NonNull LocalDate date) {
    LocalDate minDate = getMinDate();
    if (minDate != null && date.isBefore(minDate)) {
        return false;
    }
    LocalDate maxDate = getMaxDate();
    if (maxDate != null && date.isAfter(maxDate)) {
        return false;
    }
    return true;
}

86. CalendarManagerTest#testToggleViewMonthNotInView()

View license
@Test
public void testToggleViewMonthNotInView() throws Exception {
    LocalDate selected = mCalendarManager.getSelectedDay();
    LocalDate from = selected.plusMonths(1);
    RangeUnit unit = mock(RangeUnit.class);
    when(unit.isInView(selected)).thenReturn(false);
    when(unit.getFrom()).thenReturn(from);
    when(unit.getFirstDateOfCurrentMonth(any(LocalDate.class))).thenReturn(from);
    mCalendarManager.setUnit(unit);
    mCalendarManager.toggleView();
    Week week = new Week(from, LocalDate.now(), mCalendarManager.getMinDate(), mCalendarManager.getMaxDate());
    week.select(selected);
    assertEquals(week, mCalendarManager.getUnits());
    assertEquals(from.withDayOfMonth(1), mCalendarManager.getActiveMonth());
}

87. CalendarManagerTest#testToggleViewWeekInView()

View license
@Test
public void testToggleViewWeekInView() throws Exception {
    // initial state week
    mCalendarManager.toggleView();
    LocalDate currentMonth = mCalendarManager.getActiveMonth();
    LocalDate selected = mCalendarManager.getSelectedDay();
    mCalendarManager.toggleView();
    Month month = new Month(currentMonth, LocalDate.now(), mCalendarManager.getMinDate(), mCalendarManager.getMaxDate());
    month.select(selected);
    assertEquals(month, mCalendarManager.getUnits());
    assertEquals(CalendarManager.State.MONTH, mCalendarManager.getState());
}

88. CalendarManagerTest#testGetWeekInViewBefore()

View license
@Test
public void testGetWeekInViewBefore() throws Exception {
    LocalDate from = mCalendarManager.getSelectedDay().minusDays(1);
    LocalDate to = mCalendarManager.getSelectedDay().plusDays(1);
    RangeUnit unit = mock(RangeUnit.class);
    when(unit.isInView(any(LocalDate.class))).thenReturn(true);
    when(unit.isIn(any(LocalDate.class))).thenReturn(false);
    when(unit.getFrom()).thenReturn(from);
    when(unit.getTo()).thenReturn(to);
    when(unit.getWeekInMonth(to)).thenReturn(12);
    mCalendarManager.setUnit(unit);
    assertEquals(12, mCalendarManager.getWeekOfMonth());
}

89. WeekTest#testNext()

View license
@Test
public void testNext() throws Exception {
    LocalDate nextWeek = LocalDate.parse("2014-08-04");
    LocalDate nextWeekEnd = LocalDate.parse("2014-08-10");
    assertTrue(mWeek.next());
    assertEquals(nextWeek, mWeek.getFrom());
    assertEquals(nextWeekEnd, mWeek.getTo());
    assertEquals(nextWeek, mWeek.getDays().get(0).getDate());
    assertEquals(nextWeekEnd, mWeek.getDays().get(6).getDate());
}

90. WeekTest#testPrev()

View license
@Test
public void testPrev() throws Exception {
    LocalDate start = LocalDate.parse("2014-07-21");
    LocalDate end = LocalDate.parse("2014-07-27");
    assertTrue(mWeek.prev());
    assertEquals(start, mWeek.getFrom());
    assertEquals(end, mWeek.getTo());
    assertEquals(start, mWeek.getDays().get(0).getDate());
    assertEquals(end, mWeek.getDays().get(6).getDate());
}

91. TransactionsActivity#getPrettyDateFormat()

View license
/**
     * Formats the date to show the the day of the week if the {@code dateMillis} is within 7 days
     * of today. Else it shows the actual date formatted as short string. <br>
     * It also shows "today", "yesterday" or "tomorrow" if the date is on any of those days
     * @param dateMillis
     * @return
     */
@NonNull
public static String getPrettyDateFormat(Context context, long dateMillis) {
    LocalDate transactionTime = new LocalDate(dateMillis);
    LocalDate today = new LocalDate();
    String prettyDateText = null;
    if (transactionTime.compareTo(today.minusDays(1)) >= 0 && transactionTime.compareTo(today.plusDays(1)) <= 0) {
        prettyDateText = DateUtils.getRelativeTimeSpanString(dateMillis, System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS).toString();
    } else if (transactionTime.getYear() == today.getYear()) {
        prettyDateText = mDayMonthDateFormat.format(new Date(dateMillis));
    } else {
        prettyDateText = DateUtils.formatDateTime(context, dateMillis, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_YEAR);
    }
    return prettyDateText;
}

92. Cashier#fromJson()

Project: incubator-fineract
Source File: Cashier.java
View license
public static Cashier fromJson(final Office cashierOffice, final Teller teller, final Staff staff, final String startTime, final String endTime, final JsonCommand command) {
    // final Long tellerId = teller.getId();
    // final Long staffId = command.longValueOfParameterNamed("staffId");
    final String description = command.stringValueOfParameterNamed("description");
    final LocalDate startDate = command.localDateValueOfParameterNamed("startDate");
    final LocalDate endDate = command.localDateValueOfParameterNamed("endDate");
    final Boolean isFullDay = command.booleanObjectValueOfParameterNamed("isFullDay");
    return new Cashier(cashierOffice, teller, staff, description, startDate, endDate, isFullDay, startTime, endTime);
}

93. StandingInstructionAssembler#assembleStandingInstruction()

View license
public void assembleStandingInstruction(final JsonCommand command, final AccountTransferDetails accountTransferDetails) {
    final LocalDate validFrom = command.localDateValueOfParameterNamed(validFromParamName);
    final LocalDate validTill = command.localDateValueOfParameterNamed(validTillParamName);
    BigDecimal amount = null;
    final BigDecimal transferAmount = command.bigDecimalValueOfParameterNamed(amountParamName);
    if (transferAmount != null) {
        final Money monetaryAmount = Money.of(accountTransferDetails.fromSavingsAccount().getCurrency(), transferAmount);
        amount = monetaryAmount.getAmount();
    }
    final Integer status = command.integerValueOfParameterNamed(statusParamName);
    final Integer priority = command.integerValueOfParameterNamed(priorityParamName);
    final Integer standingInstructionType = command.integerValueOfParameterNamed(instructionTypeParamName);
    final Integer recurrenceType = command.integerValueOfParameterNamed(recurrenceTypeParamName);
    final Integer recurrenceFrequency = command.integerValueOfParameterNamed(recurrenceFrequencyParamName);
    final MonthDay recurrenceOnMonthDay = command.extractMonthDayNamed(recurrenceOnMonthDayParamName);
    final Integer recurrenceInterval = command.integerValueOfParameterNamed(recurrenceIntervalParamName);
    final String name = command.stringValueOfParameterNamed(nameParamName);
    AccountTransferStandingInstruction accountTransferStandingInstruction = AccountTransferStandingInstruction.create(accountTransferDetails, name, priority, standingInstructionType, status, amount, validFrom, validTill, recurrenceType, recurrenceFrequency, recurrenceInterval, recurrenceOnMonthDay);
    accountTransferDetails.updateAccountTransferStandingInstruction(accountTransferStandingInstruction);
}

94. CalendarsApiResource#retrieveCalendar()

View license
@GET
@Path("{calendarId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveCalendar(@PathParam("calendarId") final Long calendarId, @PathParam("entityType") final String entityType, @PathParam("entityId") final Long entityId, @Context final UriInfo uriInfo) {
    this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
    final Integer entityTypeId = CalendarEntityType.valueOf(entityType.toUpperCase()).getValue();
    CalendarData calendarData = this.readPlatformService.retrieveCalendar(calendarId, entityId, entityTypeId);
    // Include recurring date details
    final boolean withHistory = true;
    final LocalDate tillDate = null;
    final Collection<LocalDate> recurringDates = this.readPlatformService.generateRecurringDates(calendarData, withHistory, tillDate);
    final Collection<LocalDate> nextTenRecurringDates = this.readPlatformService.generateNextTenRecurringDates(calendarData);
    final LocalDate recentEligibleMeetingDate = null;
    calendarData = CalendarData.withRecurringDates(calendarData, recurringDates, nextTenRecurringDates, recentEligibleMeetingDate);
    final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
    if (settings.isTemplate()) {
        calendarData = handleTemplate(calendarData);
    }
    return this.toApiJsonSerializer.serialize(settings, calendarData, this.RESPONSE_DATA_PARAMETERS);
}

95. CalendarReadPlatformServiceImpl#getPeriodEndDate()

View license
private LocalDate getPeriodEndDate(LocalDate endDate, LocalDate tillDate) {
    LocalDate periodEndDate = endDate;
    final LocalDate currentDate = DateUtils.getLocalDateOfTenant();
    if (tillDate != null) {
        if (endDate != null) {
            if (endDate.isAfter(tillDate)) {
                // to retrieve meeting dates tillspecified date (tillDate)
                periodEndDate = tillDate;
            }
        } else {
            // end date is null then fetch meeting dates tillDate
            periodEndDate = tillDate;
        }
    } else if (endDate == null || endDate.isAfter(currentDate.plusYears(1))) {
        periodEndDate = currentDate.plusYears(1);
    }
    return periodEndDate;
}

96. ChargeData#toSavingsAccountChargeData()

Project: incubator-fineract
Source File: ChargeData.java
View license
public SavingsAccountChargeData toSavingsAccountChargeData() {
    final Long savingsChargeId = null;
    final Long savingsAccountId = null;
    final BigDecimal amountPaid = BigDecimal.ZERO;
    final BigDecimal amountWaived = BigDecimal.ZERO;
    final BigDecimal amountWrittenOff = BigDecimal.ZERO;
    final BigDecimal amountOutstanding = BigDecimal.ZERO;
    final BigDecimal percentage = BigDecimal.ZERO;
    final BigDecimal amountPercentageAppliedTo = BigDecimal.ZERO;
    final Collection<ChargeData> chargeOptions = null;
    final LocalDate dueAsOfDate = null;
    final Boolean isActive = null;
    final LocalDate inactivationDate = null;
    return SavingsAccountChargeData.instance(savingsChargeId, this.id, savingsAccountId, this.name, this.currency, this.amount, amountPaid, amountWaived, amountWrittenOff, amountOutstanding, this.chargeTimeType, dueAsOfDate, this.chargeCalculationType, percentage, amountPercentageAppliedTo, chargeOptions, this.penalty, this.feeOnMonthDay, this.feeInterval, isActive, inactivationDate);
}

97. ClientChargeData#template()

View license
public static ClientChargeData template(final Collection<ChargeData> chargeOptions) {
    final Long id = null;
    final Long clientId = null;
    final Long chargeId = null;
    final String name = null;
    final EnumOptionData chargeTimeType = null;
    final LocalDate dueDate = null;
    final EnumOptionData chargeCalculationType = null;
    final CurrencyData currency = null;
    final BigDecimal amount = null;
    final BigDecimal amountPaid = null;
    final BigDecimal amountWaived = null;
    final BigDecimal amountWrittenOff = null;
    final BigDecimal amountOutstanding = null;
    final Boolean penalty = false;
    final Boolean isPaid = null;
    final Boolean isActive = null;
    final Boolean isWaived = null;
    final LocalDate inactivationDate = null;
    final Collection<ClientTransactionData> clientTransactionDatas = null;
    return new ClientChargeData(id, clientId, chargeId, name, chargeTimeType, dueDate, chargeCalculationType, currency, amount, amountPaid, amountWaived, amountWrittenOff, amountOutstanding, penalty, isPaid, isWaived, isActive, inactivationDate, chargeOptions, clientTransactionDatas);
}

98. InterestRateChartData#template()

View license
public static InterestRateChartData template(Collection<EnumOptionData> periodTypes, final Collection<EnumOptionData> entityTypeOptions, final Collection<EnumOptionData> attributeNameOptions, final Collection<EnumOptionData> conditionTypeOptions, final Collection<EnumOptionData> incentiveTypeOptions, final Collection<CodeValueData> genderOptions, final Collection<CodeValueData> clientTypeOptions, final Collection<CodeValueData> clientClassificationOptions) {
    final Long id = null;
    final String name = null;
    final String description = null;
    final LocalDate fromDate = null;
    final LocalDate endDate = null;
    final boolean isPrimaryGroupingByAmount = false;
    final Long savingsProductId = null;
    final String savingsProductName = null;
    final Collection<InterestRateChartSlabData> chartSlabs = null;
    return new InterestRateChartData(id, name, description, fromDate, endDate, isPrimaryGroupingByAmount, savingsProductId, savingsProductName, chartSlabs, periodTypes, entityTypeOptions, attributeNameOptions, conditionTypeOptions, incentiveTypeOptions, genderOptions, clientTypeOptions, clientClassificationOptions);
}

99. InterestRateChartAssembler#assembleFrom()

View license
public InterestRateChart assembleFrom(final JsonElement element, final String currencyCode, final DataValidatorBuilder baseDataValidator) {
    final String name = this.fromApiJsonHelper.extractStringNamed(nameParamName, element);
    final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element);
    final LocalDate fromDate = this.fromApiJsonHelper.extractLocalDateNamed(fromDateParamName, element);
    final LocalDate toDate = this.fromApiJsonHelper.extractLocalDateNamed(endDateParamName, element);
    Boolean isPrimaryGroupingByAmount = this.fromApiJsonHelper.extractBooleanNamed(isPrimaryGroupingByAmountParamName, element);
    if (isPrimaryGroupingByAmount == null) {
        isPrimaryGroupingByAmount = false;
    }
    // assemble chart Slabs
    final Collection<InterestRateChartSlab> newChartSlabs = this.chartSlabAssembler.assembleChartSlabsFrom(element, currencyCode);
    final InterestRateChartFields fields = InterestRateChartFields.createNew(name, description, fromDate, toDate, isPrimaryGroupingByAmount);
    final InterestRateChart newChart = InterestRateChart.createNew(fields, newChartSlabs);
    newChart.validateChartSlabs(baseDataValidator);
    return newChart;
}

100. Loan#calculateOverdueAmountPercentageAppliedTo()

Project: incubator-fineract
Source File: Loan.java
View license
private BigDecimal calculateOverdueAmountPercentageAppliedTo(final LoanCharge loanCharge, final int penaltyWaitPeriod) {
    LoanRepaymentScheduleInstallment installment = loanCharge.getOverdueInstallmentCharge().getInstallment();
    LocalDate graceDate = DateUtils.getLocalDateOfTenant().minusDays(penaltyWaitPeriod);
    Money amount = Money.zero(getCurrency());
    if (graceDate.isAfter(installment.getDueDate())) {
        amount = calculateOverdueAmountPercentageAppliedTo(installment, loanCharge.getChargeCalculation());
        if (!amount.isGreaterThanZero()) {
            loanCharge.setActive(false);
        }
    } else {
        loanCharge.setActive(false);
    }
    return amount.getAmount();
}