public void shouldProcessChequeOnUs()

in component-test/src/main/java/org/apache/fineract/cn/cheque/TestCheques.java [69:117]


  public void shouldProcessChequeOnUs() throws Exception {
    final Cheque randomCheque = Fixture.createRandomCheque();

    final IssuingCount issuingCount = new IssuingCount();
    issuingCount.setAccountIdentifier(randomCheque.getMicr().getAccountNumber());
    issuingCount.setAmount(100);

    Mockito
        .doAnswer(invocation -> Collections.emptyList())
        .when(this.depositServiceSpy).getIssueChequeCharges(randomCheque.getMicr().getAccountNumber());

    super.chequeManager.issue(issuingCount);

    Assert.assertTrue(
        super.eventRecorder.wait(EventConstants.ISSUE_CHEQUES, randomCheque.getMicr().getAccountNumber())
    );

    Mockito
        .doAnswer(invocation -> true)
        .when(this.organizationServiceSpy).officeExistsByBranchSortCode(randomCheque.getMicr().getBranchSortCode());

    Mockito
        .doAnswer(invocation -> true)
        .when(this.accountingServiceSpy).accountExists(randomCheque.getMicr().getAccountNumber());

    final Account mockedAccount = new Account();
    mockedAccount.setIdentifier(randomCheque.getMicr().getAccountNumber());
    Mockito
        .doAnswer(invocation -> Optional.of(mockedAccount))
        .when(this.accountingServiceSpy).findAccount(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.PROCESSED.name(), fetchedCheque.getState());

    Mockito
        .verify(this.accountingServiceSpy, Mockito.times(1))
        .processJournalEntry(Matchers.any(JournalEntry.class));
  }