DecliningBalanceWithEqualPrincipalInstallmentsLoanInterestCalculator implements LoanInterestCalculator { @Override public Money calculate(LoanInterestCalculationDetails loanInterestCalculationDetails) { Money loanAmount = loanInterestCalculationDetails.getLoanAmount(); GraceType graceType = loanInterestCalculationDetails.getGraceType(); Integer gracePeriodDuration = loanInterestCalculationDetails.getGracePeriodDuration(); Integer numberOfInstallments = loanInterestCalculationDetails.getNumberOfInstallments(); Double interestFractionalRatePerInstallment = loanInterestCalculationDetails.getInterestFractionalRatePerInstallment(); return getDecliningEPIAmount_v2(graceType, gracePeriodDuration, numberOfInstallments, loanAmount, interestFractionalRatePerInstallment); }  @Override Money calculate(LoanInterestCalculationDetails loanInterestCalculationDetails);  }
@Test public void shouldCalculateLoanInterest() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withInterestRate("10.0") .withDurationInYears("1.0") .withGraceType(GraceType.NONE) .withGraceDurationOf(0) .withNumberOfInstallments(6) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); Money calculatedInterest = decliningBalanceWithEqualPrincipalInstallmentsLoanInterestCalculator.calculate(loanInterestCalculationDetails); assertThat(moneyOf(calculatedInterest), is(moneyOf(TestMoneyUtil.createMoney("56.0")))); }
@Test public void shouldCalculateLoanInterestWithPrincipalOnlyGrace() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withInterestRate("10.0") .withDurationInYears("1.0") .withGraceType(GraceType.PRINCIPALONLYGRACE) .withGraceDurationOf(0) .withNumberOfInstallments(6) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); Money calculatedInterest = decliningBalanceWithEqualPrincipalInstallmentsLoanInterestCalculator.calculate(loanInterestCalculationDetails); assertThat(moneyOf(calculatedInterest), is(moneyOf(TestMoneyUtil.createMoney("56.0")))); }
@Test public void shouldCalculateLoanInterestWithPrincipalOnlyGraceAndGraceDuration() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withInterestRate("10.0") .withDurationInYears("1.0") .withGraceType(GraceType.PRINCIPALONLYGRACE) .withGraceDurationOf(3) .withNumberOfInstallments(6) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); Money calculatedInterest = decliningBalanceWithEqualPrincipalInstallmentsLoanInterestCalculator.calculate(loanInterestCalculationDetails); assertThat(moneyOf(calculatedInterest), is(moneyOf(TestMoneyUtil.createMoney("80.0")))); }