@Test
  public void testGenerateScheduleInterestOnlyArrayBounds() {
    AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate();
    amAttrs.setLoanAmount(ofUSD(10000));
    amAttrs.setInterestRateAsPercent(12.);
    amAttrs.setInterestOnly(true);
    amAttrs.setPaymentFrequency(TimePeriod.Weekly.getPeriodsPerYear());
    int termInMonths = 24;
    amAttrs.setTermInMonths(termInMonths);
    amAttrs.setAdjustmentDate(LocalDate.of(2016, Month.JANUARY, 1));

    List<ScheduledPayment> schedule = AmortizationCalculator.generateSchedule(amAttrs);

    try {
      schedule.get(-1);
      fail("Interest only schedule should not allow negative payment number");
    } catch (IndexOutOfBoundsException iobe) {
    }

    int expectedPayments =
        (int) Math.ceil(amAttrs.getPaymentFrequency() * amAttrs.getTermInMonths() / 12.);

    try {
      schedule.get(expectedPayments);
      fail("Interest only schedule should not allow payments beyond schedule bound");
    } catch (IndexOutOfBoundsException iobe) {
    }

    schedule.get(expectedPayments - 1);
  }
 @Test
 public void testGetPeriodicPaymentCompoundSemiPaymentWeekly() {
   AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate();
   amAttrs.setLoanAmount(USD50000.divide(5));
   amAttrs.setInterestRateAsPercent(10.);
   amAttrs.setCompoundingPeriodsPerYear(TimePeriod.SemiAnnually.getPeriodsPerYear());
   amAttrs.setAmortizationPeriodInMonths(12);
   amAttrs.setPaymentFrequency(TimePeriod.Weekly.getPeriodsPerYear());
   MonetaryAmount result = AmortizationCalculator.getPeriodicPayment(amAttrs);
   MonetaryAmount expectedResult = ofUSD(202.04);
   assertEquals("Amortized, compounded semi-annual, payment weekly", expectedResult, result);
 }
  @Test
  public void testPaymentDateWeekly() {
    LocalDate scheduleStartDate = LocalDate.of(2015, Month.DECEMBER, 2);
    AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate();
    amAttrs.setAdjustmentDate(scheduleStartDate);
    amAttrs.setPaymentFrequency(TimePeriod.Weekly.getPeriodsPerYear());
    int termInMonths = 24;
    amAttrs.setTermInMonths(termInMonths);

    List<ScheduledPayment> schedule = AmortizationCalculator.generateSchedule(amAttrs);

    for (int i = 1; i <= (52 * 2); i++) {
      String msg = String.format("Date for weekly payment %d", i);
      assertEquals(msg, scheduleStartDate.plusWeeks(i), schedule.get(i - 1).getPaymentDate());
    }
  }