FINERACT-2181: Improve AssertJ assertions in DefaultScheduledDateGeneratorTest
This commit is contained in:
+46
-48
@@ -18,15 +18,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.fineract.portfolio.loanaccount.domain;
|
package org.apache.fineract.portfolio.loanaccount.domain;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.mockStatic;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.MathContext;
|
import java.math.MathContext;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -41,17 +44,15 @@ import org.apache.fineract.portfolio.charge.domain.ChargeCalculationType;
|
|||||||
import org.apache.fineract.portfolio.charge.domain.ChargePaymentMode;
|
import org.apache.fineract.portfolio.charge.domain.ChargePaymentMode;
|
||||||
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
|
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.MockedStatic;
|
import org.mockito.MockedStatic;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
public class SingleLoanChargeRepaymentScheduleProcessingWrapperTest {
|
public class SingleLoanChargeRepaymentScheduleProcessingWrapperTest {
|
||||||
|
|
||||||
private final SingleLoanChargeRepaymentScheduleProcessingWrapper underTest = new SingleLoanChargeRepaymentScheduleProcessingWrapper();
|
private final SingleLoanChargeRepaymentScheduleProcessingWrapper underTest = new SingleLoanChargeRepaymentScheduleProcessingWrapper();
|
||||||
private static final MockedStatic<MoneyHelper> MONEY_HELPER = Mockito.mockStatic(MoneyHelper.class);
|
private static final MockedStatic<MoneyHelper> MONEY_HELPER = mockStatic(MoneyHelper.class);
|
||||||
|
|
||||||
private MonetaryCurrency currency = MonetaryCurrency.fromCurrencyData(new CurrencyData("USD"));
|
private MonetaryCurrency currency = MonetaryCurrency.fromCurrencyData(new CurrencyData("USD"));
|
||||||
|
|
||||||
@@ -70,65 +71,63 @@ public class SingleLoanChargeRepaymentScheduleProcessingWrapperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnePeriodWithFeeCharge() {
|
public void testOnePeriodWithFeeCharge() {
|
||||||
LocalDate disbursementDate = LocalDate.of(2023, 01, 1);
|
LocalDate disbursementDate = LocalDate.of(2023, 1, 1);
|
||||||
ThreadLocalContextUtil.setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, disbursementDate)));
|
ThreadLocalContextUtil.setBusinessDates(new HashMap<>(new EnumMap<>(Map.of(BusinessDateType.BUSINESS_DATE, disbursementDate))));
|
||||||
|
|
||||||
LoanRepaymentScheduleInstallment period = createPeriod(1, LocalDate.of(2023, 01, 1), LocalDate.of(2023, 01, 30));
|
LoanRepaymentScheduleInstallment period = createPeriod(1, LocalDate.of(2023, 1, 1), LocalDate.of(2023, 1, 30));
|
||||||
LoanCharge loanCharge = createCharge(false);
|
underTest.reprocess(currency, disbursementDate, List.of(period), createCharge(false));
|
||||||
|
|
||||||
underTest.reprocess(currency, disbursementDate, List.of(period), loanCharge);
|
customVerify(period, "10.0", "0.0", "0.0", "0.0", "0.0", "0.0");
|
||||||
|
|
||||||
verify(period, "10.0", "0.0", "0.0", "0.0", "0.0", "0.0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnePeriodWithPenaltyCharge() {
|
public void testOnePeriodWithPenaltyCharge() {
|
||||||
LocalDate disbursementDate = LocalDate.of(2023, 01, 1);
|
LocalDate disbursementDate = LocalDate.of(2023, 1, 1);
|
||||||
ThreadLocalContextUtil.setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, disbursementDate)));
|
ThreadLocalContextUtil.setBusinessDates(new HashMap<>(new EnumMap<>(Map.of(BusinessDateType.BUSINESS_DATE, disbursementDate))));
|
||||||
|
|
||||||
LoanRepaymentScheduleInstallment period = createPeriod(1, LocalDate.of(2023, 01, 1), LocalDate.of(2023, 01, 30));
|
LoanRepaymentScheduleInstallment period = createPeriod(1, LocalDate.of(2023, 1, 1), LocalDate.of(2023, 1, 30));
|
||||||
LoanCharge loanCharge = createCharge(true);
|
underTest.reprocess(currency, disbursementDate, List.of(period), createCharge(true));
|
||||||
|
|
||||||
underTest.reprocess(currency, disbursementDate, List.of(period), loanCharge);
|
customVerify(period, "0.0", "0.0", "0.0", "10.0", "0.0", "0.0");
|
||||||
|
|
||||||
verify(period, "0.0", "0.0", "0.0", "10.0", "0.0", "0.0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTwoPeriodsWithPenaltyCharge() {
|
public void testTwoPeriodsWithPenaltyCharge() {
|
||||||
LocalDate disbursementDate = LocalDate.of(2023, 01, 1);
|
LocalDate disbursementDate = LocalDate.of(2023, 1, 1);
|
||||||
ThreadLocalContextUtil.setBusinessDates(new HashMap<>(Map.of(BusinessDateType.BUSINESS_DATE, disbursementDate)));
|
ThreadLocalContextUtil.setBusinessDates(new HashMap<>(new EnumMap<>(Map.of(BusinessDateType.BUSINESS_DATE, disbursementDate))));
|
||||||
|
|
||||||
LoanRepaymentScheduleInstallment period1 = createPeriod(1, LocalDate.of(2023, 01, 1), LocalDate.of(2023, 01, 31));
|
LoanRepaymentScheduleInstallment period1 = createPeriod(1, LocalDate.of(2023, 1, 1), LocalDate.of(2023, 1, 31));
|
||||||
LoanRepaymentScheduleInstallment period2 = createPeriod(1, LocalDate.of(2023, 02, 1), LocalDate.of(2023, 02, 28));
|
LoanRepaymentScheduleInstallment period2 = createPeriod(1, LocalDate.of(2023, 2, 1), LocalDate.of(2023, 2, 28));
|
||||||
|
|
||||||
LoanCharge loanCharge = createCharge(true);
|
underTest.reprocess(currency, disbursementDate, List.of(period1, period2), createCharge(true));
|
||||||
|
|
||||||
underTest.reprocess(currency, disbursementDate, List.of(period1, period2), loanCharge);
|
customVerify(period1, "0.0", "0.0", "0.0", "10.0", "0.0", "0.0");
|
||||||
|
customVerify(period2, "0.0", "0.0", "0.0", "0.0", "0.0", "0.0");
|
||||||
verify(period1, "0.0", "0.0", "0.0", "10.0", "0.0", "0.0");
|
|
||||||
verify(period2, "0.0", "0.0", "0.0", "0.0", "0.0", "0.0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verify(LoanRepaymentScheduleInstallment period, String expectedFeeChargesDue, String expectedFeeChargesWaived,
|
private void customVerify(LoanRepaymentScheduleInstallment period, String expectedFeeChargesDue, String expectedFeeChargesWaived,
|
||||||
String expectedFeeChargesWrittenOff, String expectedPenaltyChargesDue, String expectedPenaltyChargesWaived,
|
String expectedFeeChargesWrittenOff, String expectedPenaltyChargesDue, String expectedPenaltyChargesWaived,
|
||||||
String expectedPenaltyChargesWrittenOff) {
|
String expectedPenaltyChargesWrittenOff) {
|
||||||
|
|
||||||
Mockito.verify(period, times(1)).addToChargePortion(feeChargesDue.capture(), feeChargesWaived.capture(),
|
verify(period, times(1)).addToChargePortion(feeChargesDue.capture(), feeChargesWaived.capture(), feeChargesWrittenOff.capture(),
|
||||||
feeChargesWrittenOff.capture(), penaltyChargesDue.capture(), penaltyChargesWaived.capture(),
|
penaltyChargesDue.capture(), penaltyChargesWaived.capture(), penaltyChargesWrittenOff.capture());
|
||||||
penaltyChargesWrittenOff.capture());
|
|
||||||
|
|
||||||
Assertions.assertTrue(new BigDecimal(expectedFeeChargesDue).compareTo(feeChargesDue.getValue().getAmount()) == 0);
|
assertEquals(new BigDecimal(expectedFeeChargesDue).setScale(1, RoundingMode.UNNECESSARY),
|
||||||
Assertions.assertTrue(new BigDecimal(expectedFeeChargesWaived).compareTo(feeChargesWaived.getValue().getAmount()) == 0);
|
feeChargesDue.getValue().getAmount().setScale(1, RoundingMode.UNNECESSARY));
|
||||||
Assertions.assertTrue(new BigDecimal(expectedFeeChargesWrittenOff).compareTo(feeChargesWrittenOff.getValue().getAmount()) == 0);
|
assertEquals(new BigDecimal(expectedFeeChargesWaived).setScale(1, RoundingMode.UNNECESSARY),
|
||||||
Assertions.assertTrue(new BigDecimal(expectedPenaltyChargesDue).compareTo(penaltyChargesDue.getValue().getAmount()) == 0);
|
feeChargesWaived.getValue().getAmount().setScale(1, RoundingMode.UNNECESSARY));
|
||||||
Assertions.assertTrue(new BigDecimal(expectedPenaltyChargesWaived).compareTo(penaltyChargesWaived.getValue().getAmount()) == 0);
|
assertEquals(new BigDecimal(expectedFeeChargesWrittenOff).setScale(1, RoundingMode.UNNECESSARY),
|
||||||
Assertions.assertTrue(
|
feeChargesWrittenOff.getValue().getAmount().setScale(1, RoundingMode.UNNECESSARY));
|
||||||
new BigDecimal(expectedPenaltyChargesWrittenOff).compareTo(penaltyChargesWrittenOff.getValue().getAmount()) == 0);
|
assertEquals(new BigDecimal(expectedPenaltyChargesDue).setScale(1, RoundingMode.UNNECESSARY),
|
||||||
|
penaltyChargesDue.getValue().getAmount().setScale(1, RoundingMode.UNNECESSARY));
|
||||||
|
assertEquals(new BigDecimal(expectedPenaltyChargesWaived).setScale(1, RoundingMode.UNNECESSARY),
|
||||||
|
penaltyChargesWaived.getValue().getAmount().setScale(1, RoundingMode.UNNECESSARY));
|
||||||
|
assertEquals(new BigDecimal(expectedPenaltyChargesWrittenOff).setScale(1, RoundingMode.UNNECESSARY),
|
||||||
|
penaltyChargesWrittenOff.getValue().getAmount().setScale(1, RoundingMode.UNNECESSARY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static LoanCharge createCharge(boolean penalty) {
|
private LoanCharge createCharge(boolean penalty) {
|
||||||
Charge charge = mock(Charge.class);
|
Charge charge = mock(Charge.class);
|
||||||
when(charge.getId()).thenReturn(1L);
|
when(charge.getId()).thenReturn(1L);
|
||||||
when(charge.getName()).thenReturn("charge a");
|
when(charge.getName()).thenReturn("charge a");
|
||||||
@@ -136,23 +135,22 @@ public class SingleLoanChargeRepaymentScheduleProcessingWrapperTest {
|
|||||||
when(charge.isPenalty()).thenReturn(penalty);
|
when(charge.isPenalty()).thenReturn(penalty);
|
||||||
Loan loan = mock(Loan.class);
|
Loan loan = mock(Loan.class);
|
||||||
when(loan.isInterestBearing()).thenReturn(false);
|
when(loan.isInterestBearing()).thenReturn(false);
|
||||||
LoanCharge loanCharge = new LoanCharge(loan, charge, new BigDecimal(1000), new BigDecimal(10), ChargeTimeType.SPECIFIED_DUE_DATE,
|
return new LoanCharge(loan, charge, new BigDecimal(1000), new BigDecimal(10), ChargeTimeType.SPECIFIED_DUE_DATE,
|
||||||
ChargeCalculationType.FLAT, LocalDate.of(2023, 01, 15), ChargePaymentMode.REGULAR, 1, null, null);
|
ChargeCalculationType.FLAT, LocalDate.of(2023, 1, 15), ChargePaymentMode.REGULAR, 1, null, null);
|
||||||
return loanCharge;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private LoanRepaymentScheduleInstallment createPeriod(int periodId, LocalDate start, LocalDate end) {
|
private LoanRepaymentScheduleInstallment createPeriod(int periodId, LocalDate start, LocalDate end) {
|
||||||
LoanRepaymentScheduleInstallment period = Mockito.mock(LoanRepaymentScheduleInstallment.class);
|
LoanRepaymentScheduleInstallment period = mock(LoanRepaymentScheduleInstallment.class);
|
||||||
MathContext mc = new MathContext(12, RoundingMode.HALF_EVEN);
|
MathContext mc = new MathContext(12, RoundingMode.HALF_EVEN);
|
||||||
Mockito.when(period.getInstallmentNumber()).thenReturn(periodId);
|
when(period.getInstallmentNumber()).thenReturn(periodId);
|
||||||
Mockito.when(period.getFromDate()).thenReturn(start);
|
when(period.getFromDate()).thenReturn(start);
|
||||||
Mockito.when(period.getDueDate()).thenReturn(end);
|
when(period.getDueDate()).thenReturn(end);
|
||||||
Money principal = Money.of(currency, new BigDecimal("1000.0"), mc);
|
Money principal = Money.of(currency, new BigDecimal("1000.0"), mc);
|
||||||
Money interest = Money.of(currency, BigDecimal.ZERO, mc);
|
Money interest = Money.of(currency, BigDecimal.ZERO, mc);
|
||||||
|
|
||||||
Mockito.when(period.getPrincipal(eq(currency))).thenReturn(principal);
|
when(period.getPrincipal(currency)).thenReturn(principal);
|
||||||
Mockito.when(period.getInterestCharged(eq(currency))).thenReturn(interest);
|
when(period.getInterestCharged(currency)).thenReturn(interest);
|
||||||
return period;
|
return period;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-28
@@ -24,6 +24,7 @@ import java.time.OffsetDateTime;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
|
||||||
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
|
||||||
import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData;
|
import org.apache.fineract.portfolio.loanaccount.data.LoanTermVariationsData;
|
||||||
@@ -33,6 +34,9 @@ import org.junit.jupiter.api.AfterAll;
|
|||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
import org.mockito.MockedStatic;
|
import org.mockito.MockedStatic;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
@@ -57,10 +61,10 @@ public class ChangeOperationTest {
|
|||||||
ChangeOperation interestChange = createInterestRateChange("2023-10-17");
|
ChangeOperation interestChange = createInterestRateChange("2023-10-17");
|
||||||
ChangeOperation charge = createCharge("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
ChangeOperation charge = createCharge("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
||||||
ChangeOperation transaction = createTransaction("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
ChangeOperation transaction = createTransaction("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
||||||
Assertions.assertTrue(interestChange.compareTo(transaction) < 0);
|
Assertions.assertEquals(-1, interestChange.compareTo(transaction));
|
||||||
Assertions.assertTrue(interestChange.compareTo(charge) < 0);
|
Assertions.assertEquals(-1, interestChange.compareTo(charge));
|
||||||
Assertions.assertTrue(charge.compareTo(transaction) == 0);
|
Assertions.assertEquals(0, charge.compareTo(transaction));
|
||||||
Assertions.assertTrue(transaction.compareTo(charge) == 0);
|
Assertions.assertEquals(0, transaction.compareTo(charge));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -68,34 +72,37 @@ public class ChangeOperationTest {
|
|||||||
ChangeOperation interestChange = createInterestRateChange("2023-10-17");
|
ChangeOperation interestChange = createInterestRateChange("2023-10-17");
|
||||||
ChangeOperation charge = createCharge("2023-10-16", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
ChangeOperation charge = createCharge("2023-10-16", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
||||||
ChangeOperation transaction = createTransaction("2023-10-16", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
ChangeOperation transaction = createTransaction("2023-10-16", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
||||||
Assertions.assertTrue(interestChange.compareTo(transaction) > 0);
|
Assertions.assertEquals(1, interestChange.compareTo(transaction));
|
||||||
Assertions.assertTrue(interestChange.compareTo(charge) > 0);
|
Assertions.assertEquals(1, interestChange.compareTo(charge));
|
||||||
Assertions.assertTrue(charge.compareTo(transaction) == 0);
|
Assertions.assertEquals(0, charge.compareTo(transaction));
|
||||||
Assertions.assertTrue(transaction.compareTo(charge) == 0);
|
Assertions.assertEquals(0, transaction.compareTo(charge));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void testCompareToCreatedDateTime() {
|
@MethodSource("provideComparisonTestData")
|
||||||
ChangeOperation charge = createCharge("2023-10-17", "2023-10-17", "2023-10-17T10:15:31+01:00");
|
public void testComparison(String chargeEffectiveDate, String chargeSubmittedDate, String chargeCreationDateTime,
|
||||||
ChangeOperation transaction = createTransaction("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
String transactionDate, String transactionSubmittedDate, String transactionCreationDateTime, int expectedChargeVsTransaction,
|
||||||
Assertions.assertTrue(charge.compareTo(transaction) > 0);
|
int expectedTransactionVsCharge) {
|
||||||
Assertions.assertTrue(transaction.compareTo(charge) < 0);
|
ChangeOperation charge = createCharge(chargeEffectiveDate, chargeSubmittedDate, chargeCreationDateTime);
|
||||||
|
ChangeOperation transaction = createTransaction(transactionDate, transactionSubmittedDate, transactionCreationDateTime);
|
||||||
|
|
||||||
|
Assertions.assertEquals(expectedChargeVsTransaction, charge.compareTo(transaction));
|
||||||
|
Assertions.assertEquals(expectedTransactionVsCharge, transaction.compareTo(charge));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private static Stream<Arguments> provideComparisonTestData() {
|
||||||
public void testCompareToSubmittedOnDate() {
|
return Stream.of(
|
||||||
ChangeOperation charge = createCharge("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
// Test case for createdDateTime comparison
|
||||||
ChangeOperation transaction = createTransaction("2023-10-17", "2023-10-16", "2023-10-17T10:15:30+01:00");
|
Arguments.of("2023-10-17", "2023-10-17", "2023-10-17T10:15:31+01:00", "2023-10-17", "2023-10-17",
|
||||||
Assertions.assertTrue(charge.compareTo(transaction) > 0);
|
"2023-10-17T10:15:30+01:00", 1, -1),
|
||||||
Assertions.assertTrue(transaction.compareTo(charge) < 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
// Test case for submittedOnDate comparison
|
||||||
public void testComparatorEffectiveDate() {
|
Arguments.of("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00", "2023-10-17", "2023-10-16",
|
||||||
ChangeOperation charge = createCharge("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
"2023-10-17T10:15:30+01:00", 1, -1),
|
||||||
ChangeOperation transaction = createTransaction("2023-10-16", "2023-10-17", "2023-10-17T10:15:30+01:00");
|
|
||||||
Assertions.assertTrue(charge.compareTo(transaction) > 0);
|
// Test case for effectiveDate comparison
|
||||||
Assertions.assertTrue(transaction.compareTo(charge) < 0);
|
Arguments.of("2023-10-17", "2023-10-17", "2023-10-17T10:15:30+01:00", "2023-10-16", "2023-10-17",
|
||||||
|
"2023-10-17T10:15:30+01:00", 1, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -155,5 +162,4 @@ public class ChangeOperationTest {
|
|||||||
Mockito.when(transaction.getCreatedDate()).thenReturn(Optional.of(OffsetDateTime.parse(creationDateTime)));
|
Mockito.when(transaction.getCreatedDate()).thenReturn(Optional.of(OffsetDateTime.parse(creationDateTime)));
|
||||||
return new ChangeOperation(transaction);
|
return new ChangeOperation(transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
|
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -214,8 +213,13 @@ class AdvancedPaymentAllocationsValidatorTest {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<Pair<Integer, PaymentAllocationType>> createPaymentAllocationTypeList() {
|
private static List<Pair<Integer, PaymentAllocationType>> createPaymentAllocationTypeList() {
|
||||||
AtomicInteger i = new AtomicInteger(1);
|
return EnumSet.allOf(PaymentAllocationType.class).stream().map(p -> {
|
||||||
return EnumSet.allOf(PaymentAllocationType.class).stream().map(p -> Pair.of(i.getAndIncrement(), p)).toList();
|
try {
|
||||||
|
return Pair.of(Integer.parseInt(String.valueOf(Integer.parseInt(String.valueOf(p.ordinal())) + 1)), p);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new RuntimeException("Failed to create payment allocation type list", e);
|
||||||
|
}
|
||||||
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertPlatformException(String expectedMessage, String expectedCode,
|
private void assertPlatformException(String expectedMessage, String expectedCode,
|
||||||
|
|||||||
+1
-1
@@ -160,7 +160,7 @@ class LoanItemReaderTest {
|
|||||||
}
|
}
|
||||||
executorService.shutdown();
|
executorService.shutdown();
|
||||||
boolean b = executorService.awaitTermination(5L, TimeUnit.SECONDS);
|
boolean b = executorService.awaitTermination(5L, TimeUnit.SECONDS);
|
||||||
Assertions.assertTrue(b, "Executor did not terminate successfully");
|
Assertions.assertEquals(true, b, "Executor did not terminate successfully");
|
||||||
|
|
||||||
// verify that this was called 100times, and for each loan it was called exactly once
|
// verify that this was called 100times, and for each loan it was called exactly once
|
||||||
for (long i = 1; i <= 100; i++) {
|
for (long i = 1; i <= 100; i++) {
|
||||||
|
|||||||
+38
-31
@@ -105,19 +105,28 @@ public class DefaultScheduledDateGeneratorTest {
|
|||||||
loanApplicationTerms, holidayDetailDTO);
|
loanApplicationTerms, holidayDetailDTO);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result.size()).isEqualTo(4);
|
assertThat(result).hasSize(4);
|
||||||
assertThat(result.get(0).periodNumber()).isEqualTo(1);
|
assertThat(result).satisfies(periods -> {
|
||||||
assertThat(result.get(0).periodFromDate().toString()).isEqualTo("2024-01-01");
|
LoanScheduleModelPeriod firstPeriod = periods.get(0);
|
||||||
assertThat(result.get(0).periodDueDate().toString()).isEqualTo("2024-02-01");
|
assertThat(firstPeriod.periodNumber()).isEqualTo(1);
|
||||||
assertThat(result.get(1).periodNumber()).isEqualTo(2);
|
assertThat(firstPeriod.periodFromDate()).hasToString("2024-01-01");
|
||||||
assertThat(result.get(1).periodFromDate().toString()).isEqualTo("2024-02-01");
|
assertThat(firstPeriod.periodDueDate()).hasToString("2024-02-01");
|
||||||
assertThat(result.get(1).periodDueDate().toString()).isEqualTo("2024-03-01");
|
|
||||||
assertThat(result.get(2).periodNumber()).isEqualTo(3);
|
LoanScheduleModelPeriod secondPeriod = periods.get(1);
|
||||||
assertThat(result.get(2).periodFromDate().toString()).isEqualTo("2024-03-01");
|
assertThat(secondPeriod.periodNumber()).isEqualTo(2);
|
||||||
assertThat(result.get(2).periodDueDate().toString()).isEqualTo("2024-04-01");
|
assertThat(secondPeriod.periodFromDate()).hasToString("2024-02-01");
|
||||||
assertThat(result.get(3).periodNumber()).isEqualTo(4);
|
assertThat(secondPeriod.periodDueDate()).hasToString("2024-03-01");
|
||||||
assertThat(result.get(3).periodFromDate().toString()).isEqualTo("2024-04-01");
|
|
||||||
assertThat(result.get(3).periodDueDate().toString()).isEqualTo("2024-05-01");
|
LoanScheduleModelPeriod thirdPeriod = periods.get(2);
|
||||||
|
assertThat(thirdPeriod.periodNumber()).isEqualTo(3);
|
||||||
|
assertThat(thirdPeriod.periodFromDate()).hasToString("2024-03-01");
|
||||||
|
assertThat(thirdPeriod.periodDueDate()).hasToString("2024-04-01");
|
||||||
|
|
||||||
|
LoanScheduleModelPeriod fourthPeriod = periods.get(3);
|
||||||
|
assertThat(fourthPeriod.periodNumber()).isEqualTo(4);
|
||||||
|
assertThat(fourthPeriod.periodFromDate()).hasToString("2024-04-01");
|
||||||
|
assertThat(fourthPeriod.periodDueDate()).hasToString("2024-05-01");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -126,17 +135,17 @@ public class DefaultScheduledDateGeneratorTest {
|
|||||||
@WithSystemProperty(key = FLOATING_TIMEZONE_PROPERTY_KEY, value = "true")
|
@WithSystemProperty(key = FLOATING_TIMEZONE_PROPERTY_KEY, value = "true")
|
||||||
public void test_AdjustRepaymentDate_Works_WithSameTenant_And_SystemTimeZone() {
|
public void test_AdjustRepaymentDate_Works_WithSameTenant_And_SystemTimeZone() {
|
||||||
// given
|
// given
|
||||||
HolidayDetailDTO holidayDetailDTO = createHolidayDTO();
|
|
||||||
|
|
||||||
LocalDate dueRepaymentPeriodDate = LocalDate.of(2023, 11, 26);
|
LocalDate dueRepaymentPeriodDate = LocalDate.of(2023, 11, 26);
|
||||||
|
|
||||||
LoanApplicationTerms loanApplicationTerms = createLoanApplicationTerms(dueRepaymentPeriodDate, holidayDetailDTO);
|
LoanApplicationTerms loanApplicationTerms = createLoanApplicationTerms(dueRepaymentPeriodDate, createHolidayDTO());
|
||||||
// when
|
// when
|
||||||
AdjustedDateDetailsDTO result = underTest.adjustRepaymentDate(dueRepaymentPeriodDate, loanApplicationTerms, holidayDetailDTO);
|
AdjustedDateDetailsDTO result = underTest.adjustRepaymentDate(dueRepaymentPeriodDate, loanApplicationTerms, createHolidayDTO());
|
||||||
// then
|
// then
|
||||||
assertThat(result.getChangedScheduleDate()).isEqualTo(LocalDate.of(2023, 11, 26));
|
assertThat(result).satisfies(r -> {
|
||||||
assertThat(result.getChangedActualRepaymentDate()).isEqualTo(LocalDate.of(2023, 11, 26));
|
assertThat(r.getChangedScheduleDate()).isEqualTo(LocalDate.of(2023, 11, 26));
|
||||||
assertThat(result.getNextRepaymentPeriodDueDate()).isEqualTo(LocalDate.of(2023, 12, 26));
|
assertThat(r.getChangedActualRepaymentDate()).isEqualTo(LocalDate.of(2023, 11, 26));
|
||||||
|
assertThat(r.getNextRepaymentPeriodDueDate()).isEqualTo(LocalDate.of(2023, 12, 26));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -145,17 +154,17 @@ public class DefaultScheduledDateGeneratorTest {
|
|||||||
@WithSystemProperty(key = FLOATING_TIMEZONE_PROPERTY_KEY, value = "true")
|
@WithSystemProperty(key = FLOATING_TIMEZONE_PROPERTY_KEY, value = "true")
|
||||||
public void test_AdjustRepaymentDate_Works_WithDifferentTenant_And_SystemTimeZone() {
|
public void test_AdjustRepaymentDate_Works_WithDifferentTenant_And_SystemTimeZone() {
|
||||||
// given
|
// given
|
||||||
HolidayDetailDTO holidayDetailDTO = createHolidayDTO();
|
|
||||||
|
|
||||||
LocalDate dueRepaymentPeriodDate = LocalDate.of(2023, 11, 26);
|
LocalDate dueRepaymentPeriodDate = LocalDate.of(2023, 11, 26);
|
||||||
|
|
||||||
LoanApplicationTerms loanApplicationTerms = createLoanApplicationTerms(dueRepaymentPeriodDate, holidayDetailDTO);
|
LoanApplicationTerms loanApplicationTerms = createLoanApplicationTerms(dueRepaymentPeriodDate, createHolidayDTO());
|
||||||
// when
|
// when
|
||||||
AdjustedDateDetailsDTO result = underTest.adjustRepaymentDate(dueRepaymentPeriodDate, loanApplicationTerms, holidayDetailDTO);
|
AdjustedDateDetailsDTO result = underTest.adjustRepaymentDate(dueRepaymentPeriodDate, loanApplicationTerms, createHolidayDTO());
|
||||||
// then
|
// then
|
||||||
assertThat(result.getChangedScheduleDate()).isEqualTo(LocalDate.of(2023, 11, 26));
|
assertThat(result).satisfies(r -> {
|
||||||
assertThat(result.getChangedActualRepaymentDate()).isEqualTo(LocalDate.of(2023, 11, 26));
|
assertThat(r.getChangedScheduleDate()).isEqualTo(LocalDate.of(2023, 11, 26));
|
||||||
assertThat(result.getNextRepaymentPeriodDueDate()).isEqualTo(LocalDate.of(2023, 12, 26));
|
assertThat(r.getChangedActualRepaymentDate()).isEqualTo(LocalDate.of(2023, 11, 26));
|
||||||
|
assertThat(r.getNextRepaymentPeriodDueDate()).isEqualTo(LocalDate.of(2023, 12, 26));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private LoanApplicationTerms createLoanApplicationTerms(LocalDate dueRepaymentPeriodDate, HolidayDetailDTO holidayDetailDTO) {
|
private LoanApplicationTerms createLoanApplicationTerms(LocalDate dueRepaymentPeriodDate, HolidayDetailDTO holidayDetailDTO) {
|
||||||
@@ -174,10 +183,8 @@ public class DefaultScheduledDateGeneratorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private HolidayDetailDTO createHolidayDTO() {
|
private HolidayDetailDTO createHolidayDTO() {
|
||||||
WorkingDays workingDays = new WorkingDays("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA,SU", MOVE_TO_NEXT_WORKING_DAY.getValue(),
|
return new HolidayDetailDTO(false, EMPTY_LIST,
|
||||||
|
new WorkingDays("FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA,SU", MOVE_TO_NEXT_WORKING_DAY.getValue(), false, false),
|
||||||
false, false);
|
false, false);
|
||||||
HolidayDetailDTO holidayDetailDTO = new HolidayDetailDTO(false, EMPTY_LIST, workingDays, false, false);
|
|
||||||
return holidayDetailDTO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user