adamsaghy commented on code in PR #4710:
URL: https://github.com/apache/fineract/pull/4710#discussion_r2243019834
##########
fineract-provider/src/test/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImplTest.java:
##########
@@ -259,4 +313,171 @@ public void chargeOff_forReversedTransaction_shouldRun() {
assertEquals(1L, result.getClientId());
}
+
+ @Nested
+ class DisburseLoanTest {
+
+ private Loan loan;
+ private JsonCommand command;
+ private MonetaryCurrency currency;
+
+ @BeforeEach
+ void setUp() {
+ // Common setup for all disburse tests
+ setupMoneyHelper();
+ command = mock(JsonCommand.class);
+ loan = mock(Loan.class);
+ currency = new MonetaryCurrency("USD", 2, null);
+ LoanProduct loanProduct = mock(LoanProduct.class);
+ LoanProductRelatedDetail loanProductRelatedDetail =
mock(LoanProductRelatedDetail.class);
+ LoanSummary loanSummary = mock(LoanSummary.class);
+ AppUser currentUser = mock(AppUser.class);
+ LocalDate disbursementDate = LocalDate.of(2025, 5, 21);
+
+
when(command.localDateValueOfParameterNamed("adjustRepaymentDate")).thenReturn(disbursementDate);
+
when(command.localDateValueOfParameterNamed("actualDisbursementDate")).thenReturn(disbursementDate);
+
when(command.bigDecimalValueOfParameterNamed(LoanApiConstants.disbursementNetDisbursalAmountParameterName))
+ .thenReturn(BigDecimal.TEN);
+ when(command.extractLocale()).thenReturn(Locale.ENGLISH);
+ when(command.dateFormat()).thenReturn("yyyy-MM-dd");
+
+ when(loan.getId()).thenReturn(LOAN_ID);
+ when(loan.getOfficeId()).thenReturn(1L);
+ when(loan.getCurrency()).thenReturn(currency);
+ when(loan.getPrincipal()).thenReturn(Money.of(currency, new
BigDecimal("1000")));
+ when(loan.loanProduct()).thenReturn(loanProduct);
+ when(loan.getSummary()).thenReturn(loanSummary);
+
when(loan.getLoanProductRelatedDetail()).thenReturn(loanProductRelatedDetail);
+ List<LoanRepaymentScheduleInstallment> installments = new
ArrayList<>();
+ installments.add(mock(LoanRepaymentScheduleInstallment.class));
+
when(loan.getRepaymentScheduleInstallments()).thenReturn(installments);
+
when(loan.getTotalOverpaidAsMoney()).thenReturn(Money.zero(currency));
+
when(loan.fetchRepaymentScheduleInstallment(1)).thenReturn(mock(LoanRepaymentScheduleInstallment.class));
+ when(loan.getStatus()).thenReturn(LoanStatus.APPROVED);
+ when(loan.getLoanStatus()).thenReturn(LoanStatus.ACTIVE);
+
+ LoanTransaction disbursmentTransaction =
mock(LoanTransaction.class);
+
when(disbursmentTransaction.getTypeOf()).thenReturn(LoanTransactionType.DISBURSEMENT);
+
+
when(loan.getLoanTransactions()).thenReturn(List.of(disbursmentTransaction));
+
+
when(loanProduct.isDisallowExpectedDisbursements()).thenReturn(false);
+
+ when(loan.getLoanProduct()).thenReturn(loanProduct);
+ when(loanProduct.isMultiDisburseLoan()).thenReturn(false);
+
+ when(loanAssembler.assembleFrom(LOAN_ID)).thenReturn(loan);
+
when(context.getAuthenticatedUserIfPresent()).thenReturn(currentUser);
+ when(externalIdFactory.createFromCommand(any(),
any())).thenReturn(ExternalId.empty());
+ when(loanUtilService.buildScheduleGeneratorDTO(any(),
any())).thenReturn(mock(ScheduleGeneratorDTO.class));
+ when(loanDisbursementService.adjustDisburseAmount(any(), any(),
any())).thenReturn(Money.of(currency, new BigDecimal("1000")));
+
when(fineractProperties.getLoan()).thenReturn(mock(FineractProperties.FineractLoanProperties.class));
+
when(fineractProperties.getLoan().isAllowCashAndNonCashAccrual()).thenReturn(true);
+
when(loan.deriveSumTotalOfChargesDueAtDisbursement()).thenReturn(new
BigDecimal(1000));
+
when(loanLifecycleStateMachine.dryTransition(LoanEvent.LOAN_DISBURSED,
loan)).thenReturn(LoanStatus.ACTIVE);
+ when(loanRepositoryWrapper.saveAndFlush(loan)).thenReturn(loan);
+ }
+
+ @Test
+ public void
shouldApplyAccrualInterestWhenSingleDisbursementAndUpfrontAccrual() {
+
+ when(loan.isMultiDisburmentLoan()).thenReturn(false);
+
when(loan.isUpfrontAccrualAccountingEnabledOnLoanProduct()).thenReturn(true);
+
when(loan.getSummary().getTotalInterestCharged()).thenReturn(BigDecimal.TEN);
+
+ try (MockedStatic<TemporaryConfigurationServiceContainer>
temporaryConfigServiceMock =
mockStatic(TemporaryConfigurationServiceContainer.class)) {
+
+
temporaryConfigServiceMock.when(TemporaryConfigurationServiceContainer::isExternalIdAutoGenerationEnabled)
+ .thenReturn(false);
+
+ loanWritePlatformService.disburseLoan(LOAN_ID, command, false,
false);
+
+ verify(loan, times(2)).addLoanTransaction(argThat(tx ->
tx.isDisbursement() || tx.isAccrual()));
+ }
+
+ }
+
+ @Test
+ public void
shouldApplyAccrualInterestWhenMultiDisbursementFirstDisbursementAndUpfrontAccrual()
{
+
+ when(loan.isMultiDisburmentLoan()).thenReturn(true);
+
when(loan.getDisbursedLoanDisbursementDetails()).thenReturn(List.of(mock(LoanDisbursementDetails.class)));
+
when(loan.isUpfrontAccrualAccountingEnabledOnLoanProduct()).thenReturn(true);
+
when(loan.getSummary().getTotalInterestCharged()).thenReturn(BigDecimal.TEN);
+
+ try (MockedStatic<TemporaryConfigurationServiceContainer>
temporaryConfigServiceMock =
mockStatic(TemporaryConfigurationServiceContainer.class)) {
+
+
temporaryConfigServiceMock.when(TemporaryConfigurationServiceContainer::isExternalIdAutoGenerationEnabled)
+ .thenReturn(false);
+
+ loanWritePlatformService.disburseLoan(LOAN_ID, command, false,
false);
+
+ verify(loan, times(2)).addLoanTransaction(argThat(tx ->
tx.isDisbursement() || tx.isAccrual()));
+ }
+
+ }
+
+ @Test
+ public void shouldApplyAccrualInterestWhenCashAccountingIsEnabled() {
+
+ when(loan.isMultiDisburmentLoan()).thenReturn(false);
+
when(loan.isUpfrontAccrualAccountingEnabledOnLoanProduct()).thenReturn(false);
+
when(loan.isCashBasedAccountingEnabledOnLoanProduct()).thenReturn(true);
+
when(fineractProperties.getLoan().isAllowCashAndNonCashAccrual()).thenReturn(true);
+
when(loan.getSummary().getTotalInterestCharged()).thenReturn(BigDecimal.TEN);
+
+ try (MockedStatic<TemporaryConfigurationServiceContainer>
temporaryConfigServiceMock =
mockStatic(TemporaryConfigurationServiceContainer.class)) {
+
+
temporaryConfigServiceMock.when(TemporaryConfigurationServiceContainer::isExternalIdAutoGenerationEnabled)
+ .thenReturn(false);
+ loanWritePlatformService.disburseLoan(LOAN_ID, command, false,
false);
+
+ verify(loan, times(2)).addLoanTransaction(argThat(tx ->
tx.isDisbursement() || tx.isAccrual()));
Review Comment:
Little weird assertion this. Can we do it as different verifications?
one for disbursement txn and one for accrual
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]