DecliningBalanceLoanInterestCalculator implements LoanInterestCalculator { @Override public Money calculate(LoanInterestCalculationDetails loanInterestCalculationDetails) { Money loanAmount = loanInterestCalculationDetails.getLoanAmount(); Double interestRate = loanInterestCalculationDetails.getInterestRate(); GraceType graceType = loanInterestCalculationDetails.getGraceType(); Integer gracePeriodDuration = loanInterestCalculationDetails.getGracePeriodDuration(); Integer numberOfInstallments = loanInterestCalculationDetails.getNumberOfInstallments(); Double interestFractionalRatePerInstallment = loanInterestCalculationDetails.getInterestFractionalRatePerInstallment(); return getDecliningInterestAmount_v2(graceType, gracePeriodDuration, numberOfInstallments, loanAmount, interestRate, 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 = decliningBalanceLoanInterestCalculator.calculate(loanInterestCalculationDetails); assertThat(moneyOf(calculatedInterest), is(moneyOf(TestMoneyUtil.createMoney("62.8")))); }
@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 = decliningBalanceLoanInterestCalculator.calculate(loanInterestCalculationDetails); assertThat(moneyOf(calculatedInterest), is(moneyOf(TestMoneyUtil.createMoney("62.8")))); }
@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 = decliningBalanceLoanInterestCalculator.calculate(loanInterestCalculationDetails); assertThat(moneyOf(calculatedInterest), is(moneyOf(TestMoneyUtil.createMoney("81.6")))); }
@Test public void shouldCalculateLoanInterestWithZeroInterest() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withInterestRate("0.0") .withDurationInYears("1.0") .withGraceType(GraceType.PRINCIPALONLYGRACE) .withGraceDurationOf(3) .withNumberOfInstallments(6) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); Money calculatedInterest = decliningBalanceLoanInterestCalculator.calculate(loanInterestCalculationDetails); assertThat(moneyOf(calculatedInterest), is(moneyOf(TestMoneyUtil.createMoney("48.0")))); }