in component-test/src/main/java/org/apache/fineract/cn/cheque/TestCheques.java [120:163]
public void shouldApproveChequeNotOnUs() throws Exception {
final Cheque randomCheque = Fixture.createRandomCheque();
Mockito
.doAnswer(invocation -> false)
.when(this.organizationServiceSpy).officeExistsByBranchSortCode(randomCheque.getMicr().getBranchSortCode());
Mockito
.doAnswer(invocation -> false)
.when(this.accountingServiceSpy).accountExists(randomCheque.getMicr().getAccountNumber());
final ChequeTransaction chequeTransaction = new ChequeTransaction();
chequeTransaction.setCheque(randomCheque);
chequeTransaction.setChequesReceivableAccount(RandomStringUtils.randomAlphabetic(34));
chequeTransaction.setCreditorAccountNumber(RandomStringUtils.randomAlphanumeric(34));
super.chequeManager.process(chequeTransaction);
Assert.assertTrue(
super.eventRecorder.wait(EventConstants.CHEQUE_TRANSACTION, MICRParser.toIdentifier(randomCheque.getMicr()))
);
final Cheque fetchedCheque = super.chequeManager.get(MICRParser.toIdentifier(randomCheque.getMicr()));
Assert.assertNotNull(fetchedCheque);
Assert.assertEquals(State.PENDING.name(), fetchedCheque.getState());
final ChequeProcessingCommand chequeProcessingCommand = new ChequeProcessingCommand();
chequeProcessingCommand.setAction(Action.APPROVE.name());
super.chequeManager.process(MICRParser.toIdentifier(fetchedCheque.getMicr()), chequeProcessingCommand);
Assert.assertTrue(
super.eventRecorder.wait(EventConstants.CHEQUE_TRANSACTION_APPROVED,
MICRParser.toIdentifier(fetchedCheque.getMicr()))
);
final Cheque approvedCheque = super.chequeManager.get(MICRParser.toIdentifier(randomCheque.getMicr()));
Assert.assertNotNull(approvedCheque);
Assert.assertEquals(State.PROCESSED.name(), approvedCheque.getState());
Mockito
.verify(this.accountingServiceSpy, Mockito.times(1))
.processJournalEntry(Matchers.any(JournalEntry.class));
}