FINERACT-1971: added test scenarios to cover repayment schedule with large charge amounts

This commit is contained in:
Rustam Zeinalov
2025-02-27 16:37:29 +01:00
committed by Adam Saghy
parent c1ec3d7fc7
commit e1165e813a
4 changed files with 127 additions and 14 deletions
@@ -48,4 +48,26 @@ public final class Utils {
public static LocalDate now() {
return LocalDate.now(Clock.systemUTC());
}
/**
* A record that formats a double value based on whether it's a whole number or not.
* <p>
* If the value is a whole number, the output will have one decimal place (e.g., 16.0). Otherwise, it will have two
* decimal places (e.g., 16.90), but if the second decimal place is zero, it will be removed (so 16.90 becomes
* 16.9).
*/
public record DoubleFormatter(double value) {
public String format() {
boolean isWholeNumber = (value % 1.0 == 0);
String result = isWholeNumber ? String.format("%.1f", value) : String.format("%.2f", value);
// For non-whole numbers, remove trailing '0' if it exists
if (!isWholeNumber && result.endsWith("0")) {
result = result.substring(0, result.length() - 1);
}
return result;
}
}
}
@@ -1989,7 +1989,6 @@ public class LoanStepDef extends AbstractStepDef {
private List<List<String>> getActualValuesList(List<GetLoansLoanIdLoanChargeData> charges, String paymentDueAtExpected,
String dueAsOfExpected) {
List<GetLoansLoanIdLoanChargeData> result;
if (dueAsOfExpected != null) {
result = charges.stream().filter(t -> {
LocalDate dueDate = t.getDueDate();
@@ -1999,7 +1998,6 @@ public class LoanStepDef extends AbstractStepDef {
result = charges.stream().filter(t -> paymentDueAtExpected.equals(t.getChargeTimeType().getValue()))
.collect(Collectors.toList());
}
return result.stream().map(t -> {
List<String> actualValues = new ArrayList<>();
actualValues.add(t.getName() == null ? null : t.getName());
@@ -2007,10 +2005,13 @@ public class LoanStepDef extends AbstractStepDef {
actualValues.add(t.getChargeTimeType().getValue() == null ? null : t.getChargeTimeType().getValue());
actualValues.add(t.getDueDate() == null ? null : FORMATTER.format(t.getDueDate()));
actualValues.add(t.getChargeCalculationType().getValue() == null ? null : t.getChargeCalculationType().getValue());
actualValues.add(t.getAmount() == null ? null : String.valueOf(t.getAmount()));
actualValues.add(t.getAmountPaid() == null ? null : String.valueOf(t.getAmountPaid()));
actualValues.add(t.getAmountWaived() == null ? null : String.valueOf(t.getAmountWaived()));
actualValues.add(t.getAmountOutstanding() == null ? null : String.valueOf(t.getAmountOutstanding()));
actualValues.add(t.getAmount() == null ? null : new Utils.DoubleFormatter(t.getAmount()).format());
actualValues.add(t.getAmountPaid() == null ? null : new Utils.DoubleFormatter(t.getAmountPaid()).format());
actualValues.add(t.getAmountWaived() == null ? null : new Utils.DoubleFormatter(t.getAmountWaived()).format());
actualValues.add(t.getAmountOutstanding() == null ? null : new Utils.DoubleFormatter(t.getAmountOutstanding()).format());
return actualValues;
}).collect(Collectors.toList());
}
@@ -3203,12 +3204,12 @@ public class LoanStepDef extends AbstractStepDef {
actualValues.add(repaymentPeriod.getPrincipalDue() == null ? null : String.valueOf(repaymentPeriod.getPrincipalDue()));
case "Interest" ->
actualValues.add(repaymentPeriod.getInterestDue() == null ? null : String.valueOf(repaymentPeriod.getInterestDue()));
case "Fees" -> actualValues
.add(repaymentPeriod.getFeeChargesDue() == null ? null : String.valueOf(repaymentPeriod.getFeeChargesDue()));
case "Penalties" -> actualValues.add(
repaymentPeriod.getPenaltyChargesDue() == null ? null : String.valueOf(repaymentPeriod.getPenaltyChargesDue()));
case "Due" -> actualValues.add(
repaymentPeriod.getTotalDueForPeriod() == null ? null : String.valueOf(repaymentPeriod.getTotalDueForPeriod()));
case "Fees" -> actualValues.add(repaymentPeriod.getFeeChargesDue() == null ? null
: new Utils.DoubleFormatter(repaymentPeriod.getFeeChargesDue()).format());
case "Penalties" -> actualValues.add(repaymentPeriod.getPenaltyChargesDue() == null ? null
: new Utils.DoubleFormatter(repaymentPeriod.getPenaltyChargesDue()).format());
case "Due" -> actualValues.add(repaymentPeriod.getTotalDueForPeriod() == null ? null
: new Utils.DoubleFormatter(repaymentPeriod.getTotalDueForPeriod()).format());
case "Paid" -> actualValues.add(
repaymentPeriod.getTotalPaidForPeriod() == null ? null : String.valueOf(repaymentPeriod.getTotalPaidForPeriod()));
case "In advance" -> actualValues.add(repaymentPeriod.getTotalPaidInAdvanceForPeriod() == null ? null
@@ -3218,7 +3219,7 @@ public class LoanStepDef extends AbstractStepDef {
case "Waived" -> actualValues.add(repaymentPeriod.getTotalWaivedForPeriod() == null ? null
: String.valueOf(repaymentPeriod.getTotalWaivedForPeriod()));
case "Outstanding" -> actualValues.add(repaymentPeriod.getTotalOutstandingForPeriod() == null ? null
: String.valueOf(repaymentPeriod.getTotalOutstandingForPeriod()));
: new Utils.DoubleFormatter(repaymentPeriod.getTotalOutstandingForPeriod()).format());
default -> throw new IllegalStateException(String.format("Header name %s cannot be found", headerName));
}
}