budaidev commented on code in PR #6419:
URL: https://github.com/apache/fineract/pull/6419#discussion_r4029922772


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/client/feign/modules/DepositInterestCalculator.java:
##########
@@ -0,0 +1,106 @@
+/**
+ * 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.integrationtests.client.feign.modules;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Collection;
+import org.apache.fineract.client.models.GetInterestRateChartsChartSlabs;
+
+/**
+ * Projects the interest a deposit account should earn, so a test can state an 
expectation independently of the server.
+ * The arithmetic is that of the RestAssured {@code 
FixedDepositAccountHelper}: it accumulates in {@code float}, so a
+ * projection is only good to about seven significant digits and must be 
compared to the server's value with a
+ * tolerance, never for equality.
+ */
+public final class DepositInterestCalculator {
+
+    private DepositInterestCalculator() {}
+
+    /** The annual rate the chart applies to a deposit of this many periods, 
or zero when no slab covers it. */
+    public static BigDecimal 
interestRateFor(Collection<GetInterestRateChartsChartSlabs> chartSlabs, int 
depositPeriod) {
+        for (GetInterestRateChartsChartSlabs slab : chartSlabs) {
+            Integer fromPeriod = slab.getFromPeriod();
+            Integer toPeriod = slab.getToPeriod();
+            if (fromPeriod != null && toPeriod != null && depositPeriod >= 
fromPeriod && depositPeriod <= toPeriod) {

Review Comment:
   Issue: interestRateFor requires both fromPeriod and toPeriod to be non-null. 
However, DepositTestData explicitly creates final slabs with toPeriod == null 
to represent an unbounded upper range. A period in that final range therefore 
receives BigDecimal.ZERO instead of the configured interest rate.
   Impact: Deposit tests using terms in the final slab can fail incorrectly or 
use a wrong expected interest rate. It also makes the test oracle inconsistent 
with the chart data it is designed to consume.
   Recommendation: Treat a null upper bound as unbounded and add boundary tests:
   
   if (fromPeriod != null
           && depositPeriod >= fromPeriod
           && (toPeriod == null || depositPeriod <= toPeriod)) {
       return slab.getAnnualInterestRate();
   }



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