in component-test/src/main/java/org/apache/fineract/cn/payroll/TestPayrollDistribution.java [104:147]
public void shouldNotDistributePaymentsAllocatedAccountClosed() throws Exception {
final String customerIdentifier = RandomStringUtils.randomAlphanumeric(32);
final PayrollConfiguration payrollConfiguration = DomainObjectGenerator.getPayrollConfiguration();
this.prepareMocks(customerIdentifier, payrollConfiguration);
final PayrollAllocation invalidPayrollAllocation = new PayrollAllocation();
invalidPayrollAllocation.setAccountNumber(RandomStringUtils.randomAlphanumeric(34));
invalidPayrollAllocation.setProportional(Boolean.FALSE);
invalidPayrollAllocation.setAmount(BigDecimal.valueOf(200.00D));
payrollConfiguration.getPayrollAllocations().add(invalidPayrollAllocation);
final Account invalidPayrollAccount = new Account();
invalidPayrollAccount.setState(Account.State.CLOSED.name());
Mockito
.doAnswer(invocation -> Optional.of(invalidPayrollAccount))
.when(this.accountingAdaptorSpy).findAccount(Matchers.eq(invalidPayrollAllocation.getAccountNumber()));
super.testSubject.setPayrollConfiguration(customerIdentifier, payrollConfiguration);
Assert.assertTrue(super.eventRecorder.wait(EventConstants.PUT_CONFIGURATION, customerIdentifier));
final PayrollCollectionSheet payrollCollectionSheet = new PayrollCollectionSheet();
payrollCollectionSheet.setSourceAccountNumber(RandomStringUtils.randomAlphanumeric(34));
final PayrollPayment payrollPayment = new PayrollPayment();
payrollPayment.setCustomerIdentifier(customerIdentifier);
payrollPayment.setEmployer("ACME, Inc.");
payrollPayment.setSalary(BigDecimal.valueOf(1234.56D));
payrollCollectionSheet.setPayrollPayments(Lists.newArrayList(payrollPayment));
final Account sourceAccount = new Account();
sourceAccount.setState(Account.State.OPEN.name());
Mockito
.doAnswer(invocation -> Optional.of(sourceAccount))
.when(this.accountingAdaptorSpy).findAccount(Matchers.eq(payrollCollectionSheet.getSourceAccountNumber()));
Mockito
.doAnswer(invocation -> Optional.empty())
.when(this.accountingAdaptorSpy).postPayrollPayment(
Matchers.any(PayrollCollectionEntity.class),
Matchers.refEq(payrollPayment),
Matchers.any(PayrollConfiguration.class)
);
super.testSubject.distribute(payrollCollectionSheet);
}