in component-test/src/main/java/org/apache/fineract/cn/cheque/TestCheques.java [166:226]
public void shouldCancelChequeNotOnUs() 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.setChequesReceivableAccount(RandomStringUtils.randomAlphabetic(34));
chequeTransaction.setCheque(randomCheque);
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.CANCEL.name());
Mockito
.doAnswer(invocation -> {
final JournalEntry journalEntry = new JournalEntry();
journalEntry.setTransactionIdentifier(UUID.randomUUID().toString());
final Debtor debtor = new Debtor();
debtor.setAccountNumber(RandomStringUtils.randomAlphanumeric(34));
debtor.setAmount("100.00");
journalEntry.setDebtors(Sets.newHashSet(debtor));
final Creditor creditor = new Creditor();
creditor.setAccountNumber(RandomStringUtils.randomAlphanumeric(34));
creditor.setAmount("100.00");
journalEntry.setCreditors(Sets.newHashSet(creditor));
return journalEntry;
})
.when(this.accountingServiceSpy).findJournalEntry(Matchers.anyString());
super.chequeManager.process(MICRParser.toIdentifier(fetchedCheque.getMicr()), chequeProcessingCommand);
Assert.assertTrue(
super.eventRecorder.wait(EventConstants.CHEQUE_TRANSACTION_CANCELED,
MICRParser.toIdentifier(fetchedCheque.getMicr()))
);
final Cheque canceledCheque = super.chequeManager.get(MICRParser.toIdentifier(randomCheque.getMicr()));
Assert.assertNotNull(canceledCheque);
Assert.assertEquals(State.CANCELED.name(), canceledCheque.getState());
Mockito
.verify(this.accountingServiceSpy, Mockito.times(2))
.processJournalEntry(Matchers.any(JournalEntry.class));
}