LoanServiceFacadeWebTier implements LoanServiceFacade { @Override public OriginalScheduleInfoDto retrieveOriginalLoanSchedule(Integer accountId) { try { List<OriginalLoanScheduleEntity> loanScheduleEntities = loanBusinessService.retrieveOriginalLoanSchedule(accountId); ArrayList<RepaymentScheduleInstallment> repaymentScheduleInstallments = new ArrayList<RepaymentScheduleInstallment>(); for (OriginalLoanScheduleEntity loanScheduleEntity : loanScheduleEntities) { repaymentScheduleInstallments.add(loanScheduleEntity.toDto()); } LoanBO loan = this.loanDao.findById(accountId); return new OriginalScheduleInfoDto(loan.getLoanAmount().toString(),loan.getDisbursementDate(),repaymentScheduleInstallments); } catch (PersistenceException e) { throw new MifosRuntimeException(e); } } @Autowired  LoanServiceFacadeWebTier(final LoanDao loanDao, LoanBusinessService loanBusinessService); @Override OriginalScheduleInfoDto retrieveOriginalLoanSchedule(Integer accountId);  }
@Test public void retrieveOriginalLoanSchedule() throws PersistenceException { Integer accountId = new Integer(1); List<OriginalLoanScheduleEntity> loanScheduleEntities = new ArrayList<OriginalLoanScheduleEntity>(); OriginalLoanScheduleEntity originalLoanScheduleEntity1 = mock(OriginalLoanScheduleEntity.class); OriginalLoanScheduleEntity originalLoanScheduleEntity2 = mock(OriginalLoanScheduleEntity.class); loanScheduleEntities.add(originalLoanScheduleEntity1); loanScheduleEntities.add(originalLoanScheduleEntity2); RepaymentScheduleInstallment installment1 = new RepaymentScheduleInstallment(); RepaymentScheduleInstallment installment2 = new RepaymentScheduleInstallment(); when(originalLoanScheduleEntity1.toDto()).thenReturn(installment1); when(originalLoanScheduleEntity2.toDto()).thenReturn(installment2); List<RepaymentScheduleInstallment> expected = new ArrayList<RepaymentScheduleInstallment>(); expected.add(installment1); expected.add(installment2); Date date = new Date(); when(loanBO.getDisbursementDate()).thenReturn(date); Money money = new Money(rupee, "4.9"); when(loanBO.getLoanAmount()).thenReturn(money); when(loanBusinessService.retrieveOriginalLoanSchedule(accountId)).thenReturn(loanScheduleEntities); when(loanDao.findById(accountId)).thenReturn(loanBO); OriginalScheduleInfoDto expectedOriginalScheduleInfoDto = new OriginalScheduleInfoDto(money.toString(), date,expected); OriginalScheduleInfoDto originalScheduleInfoDto = loanServiceFacade.retrieveOriginalLoanSchedule(accountId); assertThat(originalScheduleInfoDto, is(new OriginalScheduleInfoDtoMatcher(expectedOriginalScheduleInfoDto))); }