FlatLoanPrincipalWithInterestGenerator implements PrincipalWithInterestGenerator { @Override public List<InstallmentPrincipalAndInterest> generateEqualInstallments(LoanInterestCalculationDetails loanInterestCalculationDetails) { GraceType graceType = loanInterestCalculationDetails.getGraceType(); Integer gracePeriodDuration = loanInterestCalculationDetails.getGracePeriodDuration(); Money loanAmount = loanInterestCalculationDetails.getLoanAmount(); Integer numberOfInstallments = loanInterestCalculationDetails.getNumberOfInstallments(); return allFlatInstallments_v2(loanInterest, graceType, loanAmount, numberOfInstallments, gracePeriodDuration); } FlatLoanPrincipalWithInterestGenerator(Money loanInterest); @Override List<InstallmentPrincipalAndInterest> generateEqualInstallments(LoanInterestCalculationDetails loanInterestCalculationDetails);  }
@Test public void shouldReturnPrincipalAndInterestDetailsForMatchingNumberOfInstallments() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withGraceType(GraceType.NONE) .withGraceDurationOf(0) .withNumberOfInstallments(1) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); List<InstallmentPrincipalAndInterest> equalInstallments = principalWithInterestGenerator.generateEqualInstallments(loanInterestCalculationDetails); assertThat(equalInstallments.size(), is(1)); }
@Test public void shouldReturnPrincipalAndInterestDetailsForMatchingNumberOfInstallments_larger() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withGraceType(GraceType.NONE) .withGraceDurationOf(0) .withNumberOfInstallments(20) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); List<InstallmentPrincipalAndInterest> equalInstallments = principalWithInterestGenerator.generateEqualInstallments(loanInterestCalculationDetails); assertThat(equalInstallments.size(), is(20)); }
@Test public void givenNoGraceOnAnyInstallmentShouldReturnPrincipalAndInterestDueForEachInstallment() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withGraceType(GraceType.NONE) .withGraceDurationOf(0) .withNumberOfInstallments(1) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); List<InstallmentPrincipalAndInterest> equalInstallments = principalWithInterestGenerator.generateEqualInstallments(loanInterestCalculationDetails); assertThat(equalInstallments.get(0).getPrincipal(), is(TestMoneyUtil.createMoney("100"))); assertThat(equalInstallments.get(0).getInterest(), is(loanInterest)); }
@Test public void givenGraceOnAllRepaymentsShouldReturnPrincipalAndInterestDueForEachInstallment() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withGraceType(GraceType.GRACEONALLREPAYMENTS) .withGraceDurationOf(0) .withNumberOfInstallments(1) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); List<InstallmentPrincipalAndInterest> equalInstallments = principalWithInterestGenerator.generateEqualInstallments(loanInterestCalculationDetails); assertThat(equalInstallments.get(0).getPrincipal(), is(TestMoneyUtil.createMoney("100"))); assertThat(equalInstallments.get(0).getInterest(), is(loanInterest)); }
@Test public void givenGraceOnAllRepaymentsShouldReturnPrincipalAndInterestDueForEachInstallmentRelativeToLoanAmount() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withGraceType(GraceType.GRACEONALLREPAYMENTS) .withGraceDurationOf(0) .withNumberOfInstallments(10) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); List<InstallmentPrincipalAndInterest> equalInstallments = principalWithInterestGenerator.generateEqualInstallments(loanInterestCalculationDetails); assertThat(equalInstallments.get(0).getPrincipal(), is(TestMoneyUtil.createMoney("10"))); assertThat(TestMoneyUtil.moneyOf(equalInstallments.get(0).getInterest()), is(TestMoneyUtil.moneyOf("0.8"))); }
@Test public void givenPrincipalOnlyGraceShouldReturnPrincipalAndInterestDueForEachInstallmentRelativeToLoanAmount() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withGraceType(GraceType.PRINCIPALONLYGRACE) .withGraceDurationOf(0) .withNumberOfInstallments(10) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); List<InstallmentPrincipalAndInterest> equalInstallments = principalWithInterestGenerator.generateEqualInstallments(loanInterestCalculationDetails); assertThat(equalInstallments.get(0).getPrincipal(), is(TestMoneyUtil.createMoney("10"))); assertThat(TestMoneyUtil.moneyOf(equalInstallments.get(0).getInterest()), is(TestMoneyUtil.moneyOf("0.8"))); }
@Test public void givenPrincipalOnlyGraceForFourInstallmentsShouldReturnPrincipalAndInterestDueForEachInstallmentRelativeToLoanAmount() { LoanInterestCalculationDetails loanInterestCalculationDetails = new LoanInterestCalculationDetailsBuilder().withLoanAmount("100.0") .withGraceType(GraceType.PRINCIPALONLYGRACE) .withGraceDurationOf(4) .withNumberOfInstallments(10) .withInterestFractionalRatePerInstallmentOf("0.16") .build(); List<InstallmentPrincipalAndInterest> equalInstallments = principalWithInterestGenerator.generateEqualInstallments(loanInterestCalculationDetails); assertThat(TestMoneyUtil.moneyOf(equalInstallments.get(0).getPrincipal()), is(TestMoneyUtil.moneyOf("0.0"))); assertThat(TestMoneyUtil.moneyOf(equalInstallments.get(0).getInterest()), is(TestMoneyUtil.moneyOf("0.8"))); }