Abhishek6122008 commented on code in PR #6782:
URL: https://github.com/apache/fineract/pull/6782#discussion_r4418254574


##########
fineract-savings/src/test/java/org/apache/fineract/portfolio/savings/service/SavingsAccountOverdraftInterestSplitTest.java:
##########
@@ -118,14 +121,58 @@ void 
overdraftSplitMonthlyPostingCountsOverdraftCarriedIntoNextMonthOnce() {
                 .isCloseTo(interestFor(withoutSplit, businessDate, 
februaryStart, februaryEnd), within(new BigDecimal("0.01")));
     }
 
+    @Test
+    void 
overdraftSplitMonthlyCompoundingChargesOverdraftInterestForDaysOverdrawnInTheSameMonth()
 {
+        final LocalDate businessDate = LocalDate.of(2025, 2, 2);
+        final LocalDate januaryEnd = LocalDate.of(2025, 1, 31);
+
+        // in credit from Jan 1 to Jan 7, then overdrawn by 10 until the month 
end: the interest of the days in
+        // credit is only compounded at the end of January, so it must not 
count for the overdrawn days
+        final SavingsAccountData withoutSplit = 
accountOverdrawnWithinFirstMonth(false, 
SavingsPostingInterestPeriodType.MONTHLY, "21");
+        final SavingsAccountData withSplit = 
accountOverdrawnWithinFirstMonth(true, 
SavingsPostingInterestPeriodType.MONTHLY, "21");
+
+        // 10,000 for 7 days at 10% and -10 for 24 days at 21%, both over 365 
days
+        assertThat(interestFor(withSplit, businessDate, ACTIVATION_DATE, 
januaryEnd, period -> !period.isOverdraftInterest()))
+                .as("interest for the days in 
credit").isEqualByComparingTo("19.18");
+        assertThat(interestFor(withSplit, businessDate, ACTIVATION_DATE, 
januaryEnd, PostingPeriod::isOverdraftInterest))
+                .as("overdraft interest for the overdrawn 
days").isEqualByComparingTo("-0.14");
+        assertThat(interestFor(withSplit, businessDate, ACTIVATION_DATE, 
januaryEnd)).as("January interest with the overdraft split")
+                .isCloseTo(interestFor(withoutSplit, businessDate, 
ACTIVATION_DATE, januaryEnd), within(new BigDecimal("0.01")));
+    }
+
+    @Test
+    void 
overdraftSplitMonthlyCompoundingPaysNoInterestForOverdrawnDaysWithoutOverdraftRate()
 {
+        final SavingsAccountData account = 
accountOverdrawnWithinFirstMonth(true, 
SavingsPostingInterestPeriodType.MONTHLY, "0");
+
+        assertThat(interestFor(account, LocalDate.of(2025, 2, 2), 
ACTIVATION_DATE, LocalDate.of(2025, 1, 31),
+                PostingPeriod::isOverdraftInterest)).as("interest for the 
overdrawn days").isEqualByComparingTo(BigDecimal.ZERO);
+    }
+
+    @Test
+    void overdraftSplitQuarterlyPostingCompoundsBothPartsAtEachMonthEnd() {
+        final LocalDate businessDate = LocalDate.of(2025, 4, 2);
+        final LocalDate quarterEnd = LocalDate.of(2025, 3, 31);
+
+        final SavingsAccountData withoutSplit = 
accountOverdrawnWithinFirstMonth(false, 
SavingsPostingInterestPeriodType.QUATERLY, "21");
+        final SavingsAccountData withSplit = 
accountOverdrawnWithinFirstMonth(true, 
SavingsPostingInterestPeriodType.QUATERLY, "21");
+
+        assertThat(interestFor(withSplit, businessDate, ACTIVATION_DATE, 
quarterEnd)).as("Q1 interest with the overdraft split")
+                .isCloseTo(interestFor(withoutSplit, businessDate, 
ACTIVATION_DATE, quarterEnd), within(new BigDecimal("0.01")));
+    }
+
     private BigDecimal interestFor(final SavingsAccountData account, final 
LocalDate businessDate, final LocalDate periodStart,
             final LocalDate periodEnd) {
+        return interestFor(account, businessDate, periodStart, periodEnd, 
period -> true);
+    }
+
+    private BigDecimal interestFor(final SavingsAccountData account, final 
LocalDate businessDate, final LocalDate periodStart,
+            final LocalDate periodEnd, final Predicate<PostingPeriod> part) {
         final List<PostingPeriod> postingPeriods = 
service.calculateInterestUsing(MATH_CONTEXT, businessDate, false, false, 1, 
null, false,
                 account);
         return postingPeriods.stream()
                 .filter(period -> 
period.getPeriodInterval().startDate().equals(periodStart)
                         && 
period.getPeriodInterval().endDate().equals(periodEnd))
-                
.map(PostingPeriod::getInterestEarned).reduce(Money.zero(CURRENCY), 
Money::plus).getAmount();
+                
.filter(part).map(PostingPeriod::getInterestEarned).reduce(Money.zero(CURRENCY),
 Money::plus).getAmount();
     }
 
     private SavingsAccountData accountWithTwoDeposits(final boolean 
allowOverdraft, final boolean interestReceivableMapped) {

Review Comment:
   The daily branch is already covered. The account in these tests compounds 
daily, so overdraftSplitMonthlyPostingCountsOverdraftCarriedIntoNextMonthOnce 
goes through it. Without the branch, January comes to -51.28 instead of -50.90 
and the test fails. I added a line to that test's comment so it's clear.



-- 
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]

Reply via email to