FINERACT-1806: Charge-off validation

This commit is contained in:
Adam Saghy
2023-02-23 10:22:10 +01:00
parent f000de5364
commit 77da04fa7d
20 changed files with 836 additions and 53 deletions
@@ -95,7 +95,7 @@ public class ExternalEventConfigurationValidationServiceTest {
"ShareAccountApproveBusinessEvent", "ShareAccountCreateBusinessEvent", "ShareProductDividentsCreateBusinessEvent",
"LoanChargeAdjustmentPostBusinessEvent", "LoanChargeAdjustmentPreBusinessEvent", "LoanDelinquencyRangeChangeBusinessEvent",
"LoanAccountsStayedLockedBusinessEvent", "MockBusinessEvent", "LoanChargeOffPreBusinessEvent",
"LoanChargeOffPostBusinessEvent");
"LoanChargeOffPostBusinessEvent", "LoanUndoChargeOffBusinessEvent");
List<FineractPlatformTenant> tenants = Arrays
.asList(new FineractPlatformTenant(1L, "default", "Default Tenant", "Europe/Budapest", null));
@@ -171,7 +171,8 @@ public class ExternalEventConfigurationValidationServiceTest {
"SavingsPostInterestBusinessEvent", "SavingsRejectBusinessEvent", "SavingsWithdrawalBusinessEvent",
"ShareAccountApproveBusinessEvent", "ShareAccountCreateBusinessEvent", "ShareProductDividentsCreateBusinessEvent",
"LoanChargeAdjustmentPostBusinessEvent", "LoanChargeAdjustmentPreBusinessEvent", "LoanDelinquencyRangeChangeBusinessEvent",
"LoanAccountsStayedLockedBusinessEvent", "LoanChargeOffPreBusinessEvent", "LoanChargeOffPostBusinessEvent");
"LoanAccountsStayedLockedBusinessEvent", "LoanChargeOffPreBusinessEvent", "LoanChargeOffPostBusinessEvent",
"LoanUndoChargeOffBusinessEvent");
List<FineractPlatformTenant> tenants = Arrays
.asList(new FineractPlatformTenant(1L, "default", "Default Tenant", "Europe/Budapest", null));
@@ -19,18 +19,23 @@
package org.apache.fineract.portfolio.loanaccount.domain;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.portfolio.charge.domain.Charge;
import org.apache.fineract.portfolio.charge.domain.ChargeCalculationType;
import org.apache.fineract.portfolio.charge.domain.ChargePaymentMode;
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.test.util.ReflectionTestUtils;
/**
@@ -76,6 +81,95 @@ public class LoanTest {
assertEquals(0, chargeIds.size());
}
/**
* Tests {@link Loan#findChargedOffTransaction()} with empty list
*/
@Test
public void testFindChargedOffTransactionEmptyList() {
final Loan loan = new Loan();
final LoanTransaction chargedOffTransaction = loan.findChargedOffTransaction();
assertNull(chargedOffTransaction);
}
/**
* Tests {@link Loan#findChargedOffTransaction()} where there is no charge-off transaction
*/
@Test
public void testFindChargedOffTransactionNoChargeOffTransaction() {
final Loan loan = new Loan();
final LoanTransaction loanTransaction = new LoanTransaction();
ReflectionTestUtils.setField(loan, "loanTransactions", List.of(loanTransaction));
final LoanTransaction chargedOffTransaction = loan.findChargedOffTransaction();
assertNull(chargedOffTransaction);
}
/**
* Tests {@link Loan#findChargedOffTransaction()} where there is charge-off transaction
*/
@Test
public void testFindChargedOffTransactionWithChargeOffTransaction() {
final Loan loan = new Loan();
final LoanTransaction loanTransaction = new LoanTransaction();
final LoanTransaction loanTransaction2 = Mockito.mock(LoanTransaction.class);
final LoanTransaction loanTransaction3 = new LoanTransaction();
when(loanTransaction2.isNotReversed()).thenReturn(Boolean.TRUE);
when(loanTransaction2.isChargeOff()).thenReturn(Boolean.TRUE);
ReflectionTestUtils.setField(loan, "loanTransactions", List.of(loanTransaction, loanTransaction2, loanTransaction3));
final LoanTransaction chargedOffTransaction = loan.findChargedOffTransaction();
assertNotNull(chargedOffTransaction);
assertEquals(loanTransaction2, chargedOffTransaction);
}
/**
* Tests {@link Loan#findChargedOffTransaction()} where there is charge-off transaction but reversed
*/
@Test
public void testFindChargedOffTransactionWithReversedChargeOffTransaction() {
final Loan loan = new Loan();
final LoanTransaction loanTransaction = new LoanTransaction();
final LoanTransaction loanTransaction2 = Mockito.mock(LoanTransaction.class);
final LoanTransaction loanTransaction3 = new LoanTransaction();
when(loanTransaction2.isReversed()).thenReturn(Boolean.TRUE);
when(loanTransaction2.isChargeOff()).thenReturn(Boolean.TRUE);
ReflectionTestUtils.setField(loan, "loanTransactions", List.of(loanTransaction, loanTransaction2, loanTransaction3));
final LoanTransaction chargedOffTransaction = loan.findChargedOffTransaction();
assertNull(chargedOffTransaction);
}
/**
* Tests {@link Loan#getLastUserTransaction()} with empty list
*/
@Test
public void testGetLastUserTransactionEmptyList() {
final Loan loan = new Loan();
final LoanTransaction userTransaction = loan.getLastUserTransaction();
assertNull(userTransaction);
}
/**
* Tests {@link Loan#getLastUserTransaction()} where there are user transactions
*/
@Test
public void testGetLastUserTransaction() {
final Loan loan = new Loan();
final LoanTransaction loanTransaction = Mockito.mock(LoanTransaction.class);
when(loanTransaction.isNotReversed()).thenReturn(Boolean.TRUE);
when(loanTransaction.isAccrualTransaction()).thenReturn(Boolean.FALSE);
final LoanTransaction loanTransaction2 = Mockito.mock(LoanTransaction.class);
when(loanTransaction2.isNotReversed()).thenReturn(Boolean.TRUE);
when(loanTransaction2.isAccrualTransaction()).thenReturn(Boolean.FALSE);
final LoanTransaction loanTransaction3 = Mockito.mock(LoanTransaction.class);
when(loanTransaction3.isNotReversed()).thenReturn(Boolean.TRUE);
when(loanTransaction3.isAccrualTransaction()).thenReturn(Boolean.TRUE);
ReflectionTestUtils.setField(loan, "loanTransactions", List.of(loanTransaction, loanTransaction2, loanTransaction3));
final LoanTransaction userTransaction = loan.getLastUserTransaction();
assertNotNull(userTransaction);
assertEquals(loanTransaction2, userTransaction);
}
/**
* Builds a new loan charge.
*