-
Notifications
You must be signed in to change notification settings - Fork 2.5k
FINERACT-1185: Add anniversary interest posting period types #5761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SamaSVM
wants to merge
1
commit into
apache:develop
Choose a base branch
from
SamaSVM:FINERACT-1185/anniversary-interest-posting
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
202 changes: 202 additions & 0 deletions
202
...ava/org/apache/fineract/portfolio/savings/domain/SavingsHelperAnniversaryPostingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.fineract.portfolio.savings.domain; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import org.apache.fineract.infrastructure.core.domain.LocalDateInterval; | ||
| import org.apache.fineract.portfolio.savings.SavingsPostingInterestPeriodType; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class SavingsHelperAnniversaryPostingTest { | ||
|
|
||
| private static final Integer FINANCIAL_YEAR_BEGINNING_MONTH = 1; | ||
|
|
||
| private final SavingsHelper savingsHelper = new SavingsHelper(null); | ||
|
|
||
| private static void assertPeriod(LocalDateInterval period, LocalDate expectedStart, LocalDate expectedEnd) { | ||
| assertThat(period.startDate()).as("period start").isEqualTo(expectedStart); | ||
| assertThat(period.endDate()).as("period end").isEqualTo(expectedEnd); | ||
| } | ||
|
|
||
| // ── ANNIVERSARY_MONTHLY ────────────────────────────────────────────────── | ||
|
|
||
| @Test | ||
| void anniversaryMonthly_accountOpenedOn15th_periodsAlignToThe15th() { | ||
| // Account opened Jan 15 → posts on Feb 15, Mar 15, Apr 15, … | ||
| LocalDate start = LocalDate.of(2024, 1, 15); | ||
| LocalDate end = LocalDate.of(2024, 3, 31); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_MONTHLY, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(3); | ||
| assertPeriod(periods.get(0), LocalDate.of(2024, 1, 15), LocalDate.of(2024, 2, 14)); | ||
| assertPeriod(periods.get(1), LocalDate.of(2024, 2, 15), LocalDate.of(2024, 3, 14)); | ||
| // last period extends past upToDate — truncation is handled by PostingPeriod, not here | ||
| assertPeriod(periods.get(2), LocalDate.of(2024, 3, 15), LocalDate.of(2024, 4, 14)); | ||
| } | ||
|
|
||
| @Test | ||
| void anniversaryMonthly_accountOpenedOn1st_periodsAlignToFirstOfMonth() { | ||
| // Day-1 anniversary: behaves identically to standard monthly-from-start | ||
| LocalDate start = LocalDate.of(2024, 1, 1); | ||
| LocalDate end = LocalDate.of(2024, 3, 31); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_MONTHLY, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(3); | ||
| assertPeriod(periods.get(0), LocalDate.of(2024, 1, 1), LocalDate.of(2024, 1, 31)); | ||
| assertPeriod(periods.get(1), LocalDate.of(2024, 2, 1), LocalDate.of(2024, 2, 29)); // 2024 leap year | ||
| assertPeriod(periods.get(2), LocalDate.of(2024, 3, 1), LocalDate.of(2024, 3, 31)); | ||
| } | ||
|
|
||
| @Test | ||
| void anniversaryMonthly_accountOpenedOn29th_februaryUsesLastDay() { | ||
| // Feb 2025 has 28 days → posting falls on Feb 28 (last day), not Feb 29 | ||
| LocalDate start = LocalDate.of(2025, 1, 29); | ||
| LocalDate end = LocalDate.of(2025, 4, 30); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_MONTHLY, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(4); | ||
| // Jan 29 → Feb 28 posting: period Jan 29 – Feb 27 | ||
| assertPeriod(periods.get(0), LocalDate.of(2025, 1, 29), LocalDate.of(2025, 2, 27)); | ||
| // Feb 28 → Mar 29 posting: period Feb 28 – Mar 28 | ||
| assertPeriod(periods.get(1), LocalDate.of(2025, 2, 28), LocalDate.of(2025, 3, 28)); | ||
| // Mar 29 → Apr 29 posting: period Mar 29 – Apr 28 | ||
| assertPeriod(periods.get(2), LocalDate.of(2025, 3, 29), LocalDate.of(2025, 4, 28)); | ||
| // Apr 29 → May 29 posting: period Apr 29 – May 28 (extends past upToDate Apr 30) | ||
| assertPeriod(periods.get(3), LocalDate.of(2025, 4, 29), LocalDate.of(2025, 5, 28)); | ||
| } | ||
|
|
||
| @Test | ||
| void anniversaryMonthly_accountOpenedOn31st_shortMonthsUseLastDay() { | ||
| // Jan 31 → Feb 28 (28 days), then Mar 31, Apr 30, May 31, Jun 30, … | ||
| LocalDate start = LocalDate.of(2025, 1, 31); | ||
| LocalDate end = LocalDate.of(2025, 5, 31); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_MONTHLY, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(5); | ||
| assertPeriod(periods.get(0), LocalDate.of(2025, 1, 31), LocalDate.of(2025, 2, 27)); // Feb 28 - 1 | ||
| assertPeriod(periods.get(1), LocalDate.of(2025, 2, 28), LocalDate.of(2025, 3, 30)); // Mar 31 - 1 | ||
| assertPeriod(periods.get(2), LocalDate.of(2025, 3, 31), LocalDate.of(2025, 4, 29)); // Apr 30 - 1 | ||
| assertPeriod(periods.get(3), LocalDate.of(2025, 4, 30), LocalDate.of(2025, 5, 30)); // May 31 - 1 | ||
| // last period extends past upToDate May 31 → May 31 – Jun 29 | ||
| assertPeriod(periods.get(4), LocalDate.of(2025, 5, 31), LocalDate.of(2025, 6, 29)); // Jun 30 - 1 | ||
| } | ||
|
|
||
| // ── ANNIVERSARY_QUARTERLY ──────────────────────────────────────────────── | ||
|
|
||
| @Test | ||
| void anniversaryQuarterly_accountOpenedOn15th_periodsAlignToThe15th() { | ||
| // Account opened Jan 15 → posts every 3 months on the 15th | ||
| LocalDate start = LocalDate.of(2024, 1, 15); | ||
| LocalDate end = LocalDate.of(2024, 12, 31); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_QUARTERLY, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(4); | ||
| assertPeriod(periods.get(0), LocalDate.of(2024, 1, 15), LocalDate.of(2024, 4, 14)); | ||
| assertPeriod(periods.get(1), LocalDate.of(2024, 4, 15), LocalDate.of(2024, 7, 14)); | ||
| assertPeriod(periods.get(2), LocalDate.of(2024, 7, 15), LocalDate.of(2024, 10, 14)); | ||
| // last period extends past Dec 31 → Oct 15 – Jan 14 2025 | ||
| assertPeriod(periods.get(3), LocalDate.of(2024, 10, 15), LocalDate.of(2025, 1, 14)); | ||
| } | ||
|
|
||
| @Test | ||
| void anniversaryQuarterly_accountOpenedOn29th_februaryQuarterUsesLastDay() { | ||
| // Nov 29 + 3 months = Feb 28 (Feb 2025 has 28 days) | ||
| LocalDate start = LocalDate.of(2024, 11, 29); | ||
| LocalDate end = LocalDate.of(2025, 5, 31); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_QUARTERLY, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(3); | ||
| // Nov 29 → Feb 28 posting: period Nov 29 – Feb 27 | ||
| assertPeriod(periods.get(0), LocalDate.of(2024, 11, 29), LocalDate.of(2025, 2, 27)); | ||
| // Feb 28 → May 29 posting: period Feb 28 – May 28 | ||
| assertPeriod(periods.get(1), LocalDate.of(2025, 2, 28), LocalDate.of(2025, 5, 28)); | ||
| // May 29 → Aug 29 posting: period May 29 – Aug 28 (extends past upToDate May 31) | ||
| assertPeriod(periods.get(2), LocalDate.of(2025, 5, 29), LocalDate.of(2025, 8, 28)); | ||
| } | ||
|
|
||
| // ── ANNIVERSARY_BIANNUAL ───────────────────────────────────────────────── | ||
|
|
||
| @Test | ||
| void anniversaryBiAnnual_accountOpenedOn15th_periodsAlignToThe15th() { | ||
| // Account opened Jan 15 → posts every 6 months on the 15th | ||
| LocalDate start = LocalDate.of(2024, 1, 15); | ||
| LocalDate end = LocalDate.of(2025, 1, 31); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_BIANNUAL, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(3); | ||
| assertPeriod(periods.get(0), LocalDate.of(2024, 1, 15), LocalDate.of(2024, 7, 14)); | ||
| assertPeriod(periods.get(1), LocalDate.of(2024, 7, 15), LocalDate.of(2025, 1, 14)); | ||
| // last period extends past Jan 31 → Jan 15 2025 – Jul 14 2025 | ||
| assertPeriod(periods.get(2), LocalDate.of(2025, 1, 15), LocalDate.of(2025, 7, 14)); | ||
| } | ||
|
|
||
| // ── ANNIVERSARY_ANNUAL ─────────────────────────────────────────────────── | ||
|
|
||
| @Test | ||
| void anniversaryAnnual_accountOpenedOn15th_periodsAlignToThe15th() { | ||
| // Account opened Mar 15 → posts annually on Mar 15 | ||
| LocalDate start = LocalDate.of(2024, 3, 15); | ||
| LocalDate end = LocalDate.of(2026, 3, 31); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_ANNUAL, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(3); | ||
| assertPeriod(periods.get(0), LocalDate.of(2024, 3, 15), LocalDate.of(2025, 3, 14)); | ||
| assertPeriod(periods.get(1), LocalDate.of(2025, 3, 15), LocalDate.of(2026, 3, 14)); | ||
| // last period extends past Mar 31 2026 → Mar 15 2026 – Mar 14 2027 | ||
| assertPeriod(periods.get(2), LocalDate.of(2026, 3, 15), LocalDate.of(2027, 3, 14)); | ||
| } | ||
|
|
||
| @Test | ||
| void anniversaryAnnual_accountOpenedOnFeb29_leapYearHandling() { | ||
| // Feb 29 2024 (leap) → next year Feb has 28 days → post on Feb 28 | ||
| LocalDate start = LocalDate.of(2024, 2, 29); | ||
| LocalDate end = LocalDate.of(2026, 3, 31); | ||
|
|
||
| List<LocalDateInterval> periods = savingsHelper.determineInterestPostingPeriods(start, end, | ||
| SavingsPostingInterestPeriodType.ANNIVERSARY_ANNUAL, FINANCIAL_YEAR_BEGINNING_MONTH, Collections.emptyList()); | ||
|
|
||
| assertThat(periods).hasSize(3); | ||
| // Feb 29 2024 → Feb 28 2025 posting: period Feb 29 2024 – Feb 27 2025 | ||
| assertPeriod(periods.get(0), LocalDate.of(2024, 2, 29), LocalDate.of(2025, 2, 27)); | ||
| // Feb 28 2025 → Feb 28 2026 posting: period Feb 28 2025 – Feb 27 2026 | ||
| assertPeriod(periods.get(1), LocalDate.of(2025, 2, 28), LocalDate.of(2026, 2, 27)); | ||
| // last period extends past Mar 31 2026 → Feb 28 2026 – Feb 27 2027 | ||
| assertPeriod(periods.get(2), LocalDate.of(2026, 2, 28), LocalDate.of(2027, 2, 27)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes looks quite breaking ones... you are effectively shifting all period end date by 1 day. Why??
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve left this logic unchanged for all non-ANNIVERSARY period types. I can try removing the plusDays(1) for the old types, but I’m not confident about the impact this might have on the rest of the logic.
Earlier we simply had the following at the end:
periodEndDate = periodEndDate.plusDays(1);return periodEndDate;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... i see.. i might need to understand this part of the logic more