org.joda.time.LocalDate

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

1. 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());
    }
}

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. 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);
}

4. 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);
}

5. 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);
}

6. 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));
}

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. 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);
}

9. 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);
}

10. 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);
}

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. 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());
}

13. 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());
}

14. 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());
}

15. 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)));
}

16. 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;
}

17. 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;
}

18. 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;
}

19. 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));
}

20. 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();
}

21. 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;
}

22. 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);
}

23. 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;
}

24. 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;
}

25. 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;
}

26. 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);
}

27. 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);
}

28. 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);
}

29. 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);
}

30. 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);
}

31. 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);
}

32. 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);
}

33. 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);
}

34. 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);
}

35. 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);
}

36. 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);
}

37. 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);
}

38. 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);
}

39. 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);
}

40. 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);
}

41. 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);
}

42. 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);
}

43. 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);
}

44. 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);
}

45. 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);
}

46. 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));
}

47. 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;
}

48. 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;
}

49. 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);
}

50. 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);
}

51. 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"));
}

52. 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"));
}

53. 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"));
}

54. 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"));
}

55. 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);
}

56. 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);
}

57. 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);
}

58. 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);
}

59. 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);
}

60. 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);
}

61. 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);
}

62. 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);
}

63. 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);
}

64. 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);
}

65. 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);
}

66. 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);
}

67. 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));
}

68. 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);
}

69. 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);
}

70. 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);
}

71. 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);
}

72. 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);
}

73. 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);
}

74. 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);
}

75. 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);
}

76. 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);
}

77. 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);
}

78. 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);
}

79. 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);
}

80. 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);
}

81. 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);
}

82. 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);
}

83. 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);
}

84. 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);
}

85. AvailabilityTimeLineTest#canBeAddedInvalidIntervals()

View license
@Test
public void canBeAddedInvalidIntervals() {
    AvailabilityTimeLine timeLine = AvailabilityTimeLine.allValid();
    LocalDate intervalStart = contemporaryExample.minusDays(10);
    LocalDate intervalEnd = contemporaryExample.plusDays(5);
    timeLine.invalidAt(intervalStart, intervalEnd);
    assertFalse("the start is inclusive", timeLine.isValid(intervalStart));
    assertFalse(timeLine.isValid(contemporaryExample.minusDays(1)));
    assertFalse(timeLine.isValid(contemporaryExample));
    assertFalse(timeLine.isValid(contemporaryExample.plusDays(1)));
    assertTrue("the end is exclusive", timeLine.isValid(intervalEnd));
}

86. StretchesFunction#intervalsFor()

Project: libreplan
Source File: StretchesFunction.java
View license
public static List<Interval> intervalsFor(ResourceAllocation<?> allocation, Collection<? extends Stretch> streches) {
    ArrayList<Interval> result = new ArrayList<>();
    LocalDate previous = null;
    LocalDate stretchDate;
    BigDecimal sumOfProportions = BigDecimal.ZERO;
    BigDecimal loadedProportion;
    for (Stretch each : streches) {
        stretchDate = each.getDateIn(allocation);
        loadedProportion = each.getAmountWorkPercentage().subtract(sumOfProportions);
        if (loadedProportion.signum() < 0) {
            loadedProportion = BigDecimal.ZERO;
        }
        result.add(Interval.create(loadedProportion, previous, stretchDate, each.isConsolidated()));
        sumOfProportions = each.getAmountWorkPercentage();
        previous = stretchDate;
    }
    return result;
}

87. ResourceAllocation#withoutAlreadyPresent()

Project: libreplan
Source File: ResourceAllocation.java
View license
private List<? extends T> withoutAlreadyPresent(Collection<? extends T> assignments) {
    if (assignments.isEmpty()) {
        return Collections.emptyList();
    }
    LocalDate min = Collections.min(assignments, DayAssignment.byDayComparator()).getDay();
    LocalDate max = Collections.max(assignments, DayAssignment.byDayComparator()).getDay();
    Set<LocalDate> daysPresent = DayAssignment.byDay(getAssignments(min, max.plusDays(1))).keySet();
    List<T> result = new ArrayList<T>();
    for (T each : assignments) {
        if (!daysPresent.contains(each.getDay())) {
            result.add(each);
        }
    }
    return result;
}

88. ResourceAllocation#resetAssigmentsFittingAllocationDatesToResultingAssignments()

Project: libreplan
Source File: ResourceAllocation.java
View license
private void resetAssigmentsFittingAllocationDatesToResultingAssignments(AllocationInterval interval, List<T> assignmentsCreated) {
    updateAssignments(interval, assignmentsCreated);
    LocalDate startConsideringAssignments = getStartConsideringAssignments();
    IntraDayDate start = IntraDayDate.startOfDay(startConsideringAssignments);
    if (interval.getStartInclusive().areSameDay(startConsideringAssignments)) {
        start = interval.getStartInclusive();
    }
    getDayAssignmentsState().setIntraDayStart(start);
    LocalDate endConsideringAssignments = getEndDateGiven(getAssignments());
    IntraDayDate end = IntraDayDate.startOfDay(endConsideringAssignments);
    if (interval.getEndExclusive().areSameDay(endConsideringAssignments)) {
        end = interval.getEndExclusive();
    }
    getDayAssignmentsState().setIntraDayEnd(end);
}

89. CostCategory#canAddHourCost()

Project: libreplan
Source File: CostCategory.java
View license
public boolean canAddHourCost(HourCost hourCost) {
    boolean overlap = false;
    LocalDate initDate = hourCost.getInitDate();
    LocalDate endDate = hourCost.getEndDate();
    for (HourCost listElement : hourCosts) {
        if (listElement.getType().getId().equals(hourCost.getType().getId())) {
            if (endDate == null && listElement.getEndDate() == null) {
                overlap = true;
            } else if ((endDate == null && listElement.getEndDate().compareTo(initDate) >= 0) || (listElement.getEndDate() == null && listElement.getInitDate().compareTo(endDate) <= 0)) {
                overlap = true;
            } else if ((endDate != null && listElement.getEndDate() != null) && ((listElement.getEndDate().compareTo(initDate) >= 0 && listElement.getEndDate().compareTo(endDate) <= 0) || (listElement.getInitDate().compareTo(initDate) >= 0 && listElement.getInitDate().compareTo(endDate) <= 0))) {
                overlap = true;
            }
        }
    }
    return !overlap;
}

90. TestDefaultRolledUpUsageDao#testNoEntries()

View license
@Test(groups = "slow")
public void testNoEntries() {
    final UUID subscriptionId = UUID.randomUUID();
    final String unitType = "foo";
    final LocalDate startDate = new LocalDate(2013, 1, 1);
    final LocalDate endDate = new LocalDate(2013, 2, 1);
    rolledUpUsageDao.record(subscriptionId, unitType, endDate, 9L, internalCallContext);
    final List<RolledUpUsageModelDao> result = rolledUpUsageDao.getUsageForSubscription(subscriptionId, startDate, endDate, unitType, internalCallContext);
    assertEquals(result.size(), 0);
}

91. TestDefaultRolledUpUsageDao#testSimple()

View license
@Test(groups = "slow")
public void testSimple() {
    final UUID subscriptionId = UUID.randomUUID();
    final String unitType = "foo";
    final LocalDate startDate = new LocalDate(2013, 1, 1);
    final LocalDate endDate = new LocalDate(2013, 2, 1);
    final Long amount1 = 10L;
    final Long amount2 = 5L;
    rolledUpUsageDao.record(subscriptionId, unitType, startDate, amount1, internalCallContext);
    rolledUpUsageDao.record(subscriptionId, unitType, endDate.minusDays(1), amount2, internalCallContext);
    final List<RolledUpUsageModelDao> result = rolledUpUsageDao.getUsageForSubscription(subscriptionId, startDate, endDate, unitType, internalCallContext);
    assertEquals(result.size(), 2);
    assertEquals(result.get(0).getSubscriptionId(), subscriptionId);
    assertEquals(result.get(0).getRecordDate().compareTo(startDate), 0);
    assertEquals(result.get(0).getUnitType(), unitType);
    assertEquals(result.get(0).getAmount().compareTo(amount1), 0);
    assertEquals(result.get(1).getSubscriptionId(), subscriptionId);
    assertEquals(result.get(1).getRecordDate().compareTo(endDate.minusDays(1)), 0);
    assertEquals(result.get(1).getUnitType(), unitType);
    assertEquals(result.get(1).getAmount().compareTo(amount2), 0);
}

92. DefaultUsageUserApi#getAllUsageForSubscription()

Project: killbill
Source File: DefaultUsageUserApi.java
View license
@Override
public List<RolledUpUsage> getAllUsageForSubscription(final UUID subscriptionId, final List<LocalDate> transitionTimes, final TenantContext tenantContext) {
    final InternalTenantContext internalCallContext = internalCallContextFactory.createInternalTenantContext(subscriptionId, ObjectType.SUBSCRIPTION, tenantContext);
    List<RolledUpUsage> result = new ArrayList<RolledUpUsage>();
    LocalDate prevDate = null;
    for (LocalDate curDate : transitionTimes) {
        if (prevDate != null) {
            final List<RolledUpUsageModelDao> usageForSubscription = rolledUpUsageDao.getAllUsageForSubscription(subscriptionId, prevDate, curDate, internalCallContext);
            final List<RolledUpUnit> rolledUpAmount = getRolledUpUnits(usageForSubscription);
            result.add(new DefaultRolledUpUsage(subscriptionId, prevDate, curDate, rolledUpAmount));
        }
        prevDate = curDate;
    }
    return result;
}

93. UsageResource#getAllUsage()

Project: killbill
Source File: UsageResource.java
View license
@TimedResource
@GET
@Path("/{subscriptionId:" + UUID_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve usage for a subscription", response = RolledUpUsageJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Missing start date or end date") })
public Response getAllUsage(@PathParam("subscriptionId") final String subscriptionId, @QueryParam(QUERY_START_DATE) final String startDate, @QueryParam(QUERY_END_DATE) final String endDate, @javax.ws.rs.core.Context final HttpServletRequest request) {
    if (startDate == null || endDate == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    final TenantContext tenantContext = context.createContext(request);
    final LocalDate usageStartDate = LOCAL_DATE_FORMATTER.parseLocalDate(startDate);
    final LocalDate usageEndDate = LOCAL_DATE_FORMATTER.parseLocalDate(endDate);
    // The current JAXRS API only allows to look for one transition
    final List<LocalDate> startEndDate = ImmutableList.<LocalDate>builder().add(usageStartDate).add(usageEndDate).build();
    final List<RolledUpUsage> usage = usageUserApi.getAllUsageForSubscription(UUID.fromString(subscriptionId), startEndDate, tenantContext);
    final RolledUpUsageJson result = new RolledUpUsageJson(usage.get(0));
    return Response.status(Status.OK).entity(result).build();
}

94. UsageResource#getUsage()

Project: killbill
Source File: UsageResource.java
View license
@TimedResource
@GET
@Path("/{subscriptionId:" + UUID_PATTERN + "}/{unitType}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve usage for a subscription and unit type", response = RolledUpUsageJson.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Missing start date or end date") })
public Response getUsage(@PathParam("subscriptionId") final String subscriptionId, @PathParam("unitType") final String unitType, @QueryParam(QUERY_START_DATE) final String startDate, @QueryParam(QUERY_END_DATE) final String endDate, @javax.ws.rs.core.Context final HttpServletRequest request) {
    if (startDate == null || endDate == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    final TenantContext tenantContext = context.createContext(request);
    final LocalDate usageStartDate = LOCAL_DATE_FORMATTER.parseLocalDate(startDate);
    final LocalDate usageEndDate = LOCAL_DATE_FORMATTER.parseLocalDate(endDate);
    final RolledUpUsage usage = usageUserApi.getUsageForSubscription(UUID.fromString(subscriptionId), unitType, usageStartDate, usageEndDate, tenantContext);
    final RolledUpUsageJson result = new RolledUpUsageJson(usage);
    return Response.status(Status.OK).entity(result).build();
}

95. TestSubscriptionItemTree#testMergeWithNoExisting()

View license
@Test(groups = "fast")
public void testMergeWithNoExisting() {
    final LocalDate startDate = new LocalDate(2014, 1, 1);
    final LocalDate endDate = new LocalDate(2014, 2, 1);
    final BigDecimal monthlyRate = new BigDecimal("12.00");
    final BigDecimal monthlyAmount = monthlyRate;
    final SubscriptionItemTree tree = new SubscriptionItemTree(subscriptionId, invoiceId);
    tree.flatten(true);
    final InvoiceItem proposed1 = new RecurringInvoiceItem(invoiceId, accountId, bundleId, subscriptionId, planName, phaseName, startDate, endDate, monthlyAmount, monthlyRate, currency);
    tree.mergeProposedItem(proposed1);
    tree.buildForMerge();
    final List<InvoiceItem> expectedResult = Lists.newLinkedList();
    expectedResult.add(proposed1);
    verifyResult(tree.getView(), expectedResult);
}

96. RecurringDepositAccount#calculateMaturityDate()

View license
public LocalDate calculateMaturityDate() {
    final LocalDate startDate = depositStartDate();
    LocalDate maturityDate = null;
    final Integer depositPeriod = this.accountTermAndPreClosure.depositPeriod();
    if (depositPeriod == null) {
        return maturityDate;
    }
    switch(this.accountTermAndPreClosure.depositPeriodFrequencyType()) {
        case DAYS:
            maturityDate = startDate.plusDays(depositPeriod);
            break;
        case WEEKS:
            maturityDate = startDate.plusWeeks(depositPeriod);
            break;
        case MONTHS:
            maturityDate = startDate.plusMonths(depositPeriod);
            break;
        case YEARS:
            maturityDate = startDate.plusYears(depositPeriod);
            break;
        case INVALID:
            break;
    }
    return maturityDate;
}

97. SavingsHelper#determineInterestPostingPeriods()

View license
public List<LocalDateInterval> determineInterestPostingPeriods(final LocalDate startInterestCalculationLocalDate, final LocalDate interestPostingUpToDate, final SavingsPostingInterestPeriodType postingPeriodType, final Integer financialYearBeginningMonth) {
    final List<LocalDateInterval> postingPeriods = new ArrayList<>();
    LocalDate periodStartDate = startInterestCalculationLocalDate;
    LocalDate periodEndDate = periodStartDate;
    while (!periodStartDate.isAfter(interestPostingUpToDate) && !periodEndDate.isAfter(interestPostingUpToDate)) {
        final LocalDate interestPostingLocalDate = determineInterestPostingPeriodEndDateFrom(periodStartDate, postingPeriodType, interestPostingUpToDate, financialYearBeginningMonth);
        periodEndDate = interestPostingLocalDate.minusDays(1);
        postingPeriods.add(LocalDateInterval.create(periodStartDate, periodEndDate));
        periodEndDate = interestPostingLocalDate;
        periodStartDate = interestPostingLocalDate;
    }
    return postingPeriods;
}

98. DepositAccountWritePlatformServiceJpaRepositoryImpl#applyChargeDue()

View license
@Transactional
@Override
public void applyChargeDue(final Long savingsAccountChargeId, final Long accountId, @SuppressWarnings("unused") final DepositAccountType depositAccountType) {
    // always use current date as transaction date for batch job
    final LocalDate transactionDate = DateUtils.getLocalDateOfTenant();
    final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository.findOneWithNotFoundDetection(savingsAccountChargeId, accountId);
    final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy");
    while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate())) {
        payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt);
    }
}

99. TestHtmlInvoiceGenerator#createInvoice()

View license
private Invoice createInvoice() {
    final LocalDate startDate = new LocalDate(new DateTime().minusMonths(1), DateTimeZone.UTC);
    final LocalDate endDate = new LocalDate(DateTimeZone.UTC);
    final BigDecimal price1 = new BigDecimal("29.95");
    final BigDecimal price2 = new BigDecimal("59.95");
    final Invoice dummyInvoice = Mockito.mock(Invoice.class);
    Mockito.when(dummyInvoice.getInvoiceDate()).thenReturn(startDate);
    Mockito.when(dummyInvoice.getInvoiceNumber()).thenReturn(42);
    Mockito.when(dummyInvoice.getCurrency()).thenReturn(Currency.USD);
    Mockito.when(dummyInvoice.getChargedAmount()).thenReturn(price1.add(price2));
    Mockito.when(dummyInvoice.getPaidAmount()).thenReturn(BigDecimal.ZERO);
    Mockito.when(dummyInvoice.getBalance()).thenReturn(price1.add(price2));
    final List<InvoiceItem> items = new ArrayList<InvoiceItem>();
    items.add(createInvoiceItem(price1, "Domain 1", startDate, endDate, "ning-plus"));
    items.add(createInvoiceItem(price2, "Domain 2", startDate, endDate, "ning-pro"));
    Mockito.when(dummyInvoice.getInvoiceItems()).thenReturn(items);
    return dummyInvoice;
}

100. FixedDepositAccount#calculateMaturityDate()

View license
public LocalDate calculateMaturityDate() {
    final LocalDate startDate = accountSubmittedOrActivationDate();
    LocalDate maturityDate = null;
    final Integer depositPeriod = this.accountTermAndPreClosure.depositPeriod();
    switch(this.accountTermAndPreClosure.depositPeriodFrequencyType()) {
        case DAYS:
            maturityDate = startDate.plusDays(depositPeriod);
            break;
        case WEEKS:
            maturityDate = startDate.plusWeeks(depositPeriod);
            break;
        case MONTHS:
            maturityDate = startDate.plusMonths(depositPeriod);
            break;
        case YEARS:
            maturityDate = startDate.plusYears(depositPeriod);
            break;
        case INVALID:
            break;
    }
    return maturityDate;
}