@Test
  public void testGetPaymentsAmortizedFully() {

    AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate();
    MonetaryAmount loanAmount = ofUSD(10000);
    amAttrs.setLoanAmount(loanAmount);
    amAttrs.setInterestRateAsPercent(7.);
    amAttrs.setInterestOnly(false);
    amAttrs.setPaymentFrequency(TimePeriod.Monthly.getPeriodsPerYear());
    int termInMonths = 12;
    amAttrs.setTermInMonths(termInMonths);
    amAttrs.setAmortizationPeriodInMonths(12);
    amAttrs.setCompoundingPeriodsPerYear(2);
    amAttrs.setRegularPayment(AmortizationCalculator.getPeriodicPayment(amAttrs));

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

    MonetaryAmount interestTotal =
        schedule.stream().map(payment -> payment.getInterest()).reduce((a, b) -> a.add(b)).get();

    assertEquals("Amortized Interest total", ofUSD(377.67), interestTotal);

    MonetaryAmount principalTotal =
        schedule.stream().map(payment -> payment.getPrincipal()).reduce((a, b) -> a.add(b)).get();

    assertEquals("Amortized Principal fully paid", loanAmount, principalTotal);
  }
  @Test
  public void testGenerateScheduleInterestOnlyMonthly() {
    AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate();
    amAttrs.setLoanAmount(ofUSD(10000));
    amAttrs.setInterestRateAsPercent(10.);
    amAttrs.setInterestOnly(true);
    amAttrs.setPaymentFrequency(TimePeriod.Monthly.getPeriodsPerYear());
    int termInMonths = 12;
    amAttrs.setTermInMonths(termInMonths);
    amAttrs.setAdjustmentDate(LocalDate.of(2016, Month.JANUARY, 1));
    amAttrs.setRegularPayment(ofUSD(0));

    List<ScheduledPayment> schedule = AmortizationCalculator.generateSchedule(amAttrs);
    assertEquals("Interest only schedule term in months", termInMonths, schedule.size());

    MonetaryAmount expectedInterest = ofUSD(83.34);
    MonetaryAmount expectedPrincipal = ofUSD(0);
    LocalDate expectedDate = amAttrs.getAdjustmentDate();
    int index = 0;

    for (ScheduledPayment payment : schedule) {
      expectedDate = expectedDate.plusMonths(1L);
      assertEquals("Interest only schedule payment number", ++index, payment.getPaymentNumber());
      assertEquals("Interest only schedule payment date", expectedDate, payment.getPaymentDate());
      assertEquals(
          "Interest only schedule payment interest", expectedInterest, payment.getInterest());
      assertEquals(
          "Interest only schedule payment principal", expectedPrincipal, payment.getPrincipal());
      assertEquals(
          "Interest only schedule payment total payment", expectedInterest, payment.getPayment());
      assertEquals(
          "Interest only schedule payment loan principal", ofUSD(10000), payment.getBalance());
    }
  }
 @Test
 public void testGetPeriodicPaymentCompoundSemiPaymentMonthly() {
   AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate();
   amAttrs.setLoanAmount(USD50000.divide(5));
   amAttrs.setInterestRateAsPercent(10.);
   amAttrs.setCompoundingPeriodsPerYear(TimePeriod.SemiAnnually.getPeriodsPerYear());
   amAttrs.setAmortizationPeriodInMonths(12);
   amAttrs.setPaymentFrequency(TimePeriod.Monthly.getPeriodsPerYear());
   MonetaryAmount result = AmortizationCalculator.getPeriodicPayment(amAttrs);
   MonetaryAmount expectedResult = ofUSD(878.22);
   assertEquals("Amortized, compounded semi-annual, payment monthly", expectedResult, result);
 }
  @Test
  public void testGetPaymentsAmortized() {

    AmortizationAttributes amAttrs = generateAmortizationAttributesObjectTemplate();
    amAttrs.setLoanAmount(ofUSD(200000));
    amAttrs.setInterestRateAsPercent(8.);
    amAttrs.setInterestOnly(false);
    amAttrs.setPaymentFrequency(TimePeriod.Monthly.getPeriodsPerYear());
    int termInMonths = 36;
    amAttrs.setTermInMonths(termInMonths);
    amAttrs.setAmortizationPeriodInMonths(20 * 12);
    amAttrs.setCompoundingPeriodsPerYear(2);
    amAttrs.setRegularPayment(AmortizationCalculator.getPeriodicPayment(amAttrs));

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

    assertEquals("Amortized payment count", termInMonths, schedule.size());

    MonetaryAmount interestTotal =
        schedule.stream().map(payment -> payment.getInterest()).reduce((a, b) -> a.add(b)).get();

    assertEquals("Amortized Interest total", ofUSD(45681.29), interestTotal);
  }
 @Test
 public void testPaymentDateMonthly() {
   testPaymentDatesWithMonthlyIntervals(TimePeriod.Monthly.getPeriodsPerYear());
 }