FINERACT-2181: No Accrual Activity for not active loans
This commit is contained in:
committed by
Arnold Gálovics
parent
d947183529
commit
815421fd94
+1
-1
@@ -65,7 +65,7 @@ public class LoanAccrualActivityProcessingServiceImpl implements LoanAccrualActi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void makeAccrualActivityTransaction(@NotNull Loan loan, @NotNull LocalDate currentDate) {
|
public void makeAccrualActivityTransaction(@NotNull Loan loan, @NotNull LocalDate currentDate) {
|
||||||
if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting() || loan.isClosed() || loan.getStatus().isOverpaid()) {
|
if (!loan.getLoanProductRelatedDetail().isEnableAccrualActivityPosting() || !loan.isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// check if loan has installment in the past or due on current date
|
// check if loan has installment in the past or due on current date
|
||||||
|
|||||||
+30
-27
@@ -26,17 +26,13 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.stream.Stream;
|
import java.util.ArrayList;
|
||||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanAccountService;
|
import org.apache.fineract.portfolio.loanaccount.domain.LoanAccountService;
|
||||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
|
|
||||||
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRelatedDetail;
|
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRelatedDetail;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
@@ -53,9 +49,6 @@ public class LoanAccrualActivityProcessingServiceImplTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Loan loan;
|
private Loan loan;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private LoanStatus loanStatus;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private LoanProductRelatedDetail loanProductRelatedDetail;
|
private LoanProductRelatedDetail loanProductRelatedDetail;
|
||||||
|
|
||||||
@@ -68,22 +61,12 @@ public class LoanAccrualActivityProcessingServiceImplTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private LoanTransactionAssembler loanTransactionAssembler;
|
private LoanTransactionAssembler loanTransactionAssembler;
|
||||||
|
|
||||||
@BeforeEach
|
@Test
|
||||||
void setUp() {
|
void addPeriodicAccruals_ShouldNotProceed_WhenLoanIsNotOpen() {
|
||||||
when(loan.isClosed()).thenReturn(false);
|
|
||||||
when(loan.getStatus()).thenReturn(loanStatus);
|
|
||||||
when(loanStatus.isOverpaid()).thenReturn(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("loanStatusTestCases")
|
|
||||||
void addPeriodicAccruals_ShouldNotProceed_WhenLoanIsClosedOrOverpaid(final boolean isClosed, final boolean isOverpaid) {
|
|
||||||
// Given
|
// Given
|
||||||
final LocalDate currentDate = LocalDate.now(ZoneId.systemDefault());
|
final LocalDate currentDate = LocalDate.now(ZoneId.systemDefault());
|
||||||
when(loan.isClosed()).thenReturn(isClosed);
|
|
||||||
|
|
||||||
when(loan.getStatus()).thenReturn(loanStatus);
|
when(loan.isOpen()).thenReturn(false);
|
||||||
when(loanStatus.isOverpaid()).thenReturn(isOverpaid);
|
|
||||||
|
|
||||||
when(loan.getLoanProductRelatedDetail()).thenReturn(loanProductRelatedDetail);
|
when(loan.getLoanProductRelatedDetail()).thenReturn(loanProductRelatedDetail);
|
||||||
when(loanProductRelatedDetail.isEnableAccrualActivityPosting()).thenReturn(true);
|
when(loanProductRelatedDetail.isEnableAccrualActivityPosting()).thenReturn(true);
|
||||||
@@ -92,7 +75,7 @@ public class LoanAccrualActivityProcessingServiceImplTest {
|
|||||||
accrualActivityProcessingService.makeAccrualActivityTransaction(loan, currentDate);
|
accrualActivityProcessingService.makeAccrualActivityTransaction(loan, currentDate);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
verify(loan, times(1)).isClosed();
|
verify(loan, times(1)).isOpen();
|
||||||
|
|
||||||
verify(loan, never()).getRepaymentScheduleInstallments(any());
|
verify(loan, never()).getRepaymentScheduleInstallments(any());
|
||||||
verify(loan, never()).addLoanTransaction(any());
|
verify(loan, never()).addLoanTransaction(any());
|
||||||
@@ -102,9 +85,29 @@ public class LoanAccrualActivityProcessingServiceImplTest {
|
|||||||
verify(businessEventNotifierService, never()).notifyPostBusinessEvent(any());
|
verify(businessEventNotifierService, never()).notifyPostBusinessEvent(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Arguments> loanStatusTestCases() {
|
@Test
|
||||||
return Stream.of(Arguments.of(true, false), // Loan is closed
|
void addPeriodicAccruals_ShouldProceed_WhenLoanIsOpen() {
|
||||||
Arguments.of(false, true) // Loan is overpaid
|
// Given
|
||||||
);
|
final LocalDate currentDate = LocalDate.now(ZoneId.systemDefault());
|
||||||
|
|
||||||
|
when(loan.isOpen()).thenReturn(true);
|
||||||
|
|
||||||
|
when(loan.getLoanProductRelatedDetail()).thenReturn(loanProductRelatedDetail);
|
||||||
|
when(loanProductRelatedDetail.isEnableAccrualActivityPosting()).thenReturn(true);
|
||||||
|
when(loan.getRepaymentScheduleInstallments()).thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
|
// When
|
||||||
|
accrualActivityProcessingService.makeAccrualActivityTransaction(loan, currentDate);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
verify(loan, times(1)).isOpen();
|
||||||
|
|
||||||
|
verify(loan).getRepaymentScheduleInstallments(any());
|
||||||
|
verify(loan, never()).addLoanTransaction(any());
|
||||||
|
verify(loanAccountService, never()).saveLoanTransactionWithDataIntegrityViolationChecks(any());
|
||||||
|
verify(loanTransactionAssembler, never()).assembleAccrualActivityTransaction(any(), any(), any());
|
||||||
|
verify(businessEventNotifierService, never()).notifyPreBusinessEvent(any());
|
||||||
|
verify(businessEventNotifierService, never()).notifyPostBusinessEvent(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user