adamsaghy commented on code in PR #3791:
URL: https://github.com/apache/fineract/pull/3791#discussion_r1528192688
##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/FixedDepositTest.java:
##########
@@ -126,6 +137,65 @@ public void setup() {
TimeZone.setDefault(TimeZone.getTimeZone(Utils.TENANT_TIME_ZONE));
}
+ /***
+ * Test case for Fixed Deposit Account Interest Calculation
+ */
+ @Test
+ public void
testFixedDepositInterestCalculationWithWrongCompoundingPeriod() {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("principalAmount", 100);
+ jsonObject.addProperty("annualInterestRate", 5);
+ jsonObject.addProperty("tenureInMonths", 12);
+ jsonObject.addProperty("interestPostingPeriodInMonths", 3);
+ jsonObject.addProperty("interestCompoundingPeriodInMonths", 7);
+ JsonParser parser = new JsonParser();
+ String apiRequestBodyAsJson = jsonObject.toString();
+ JsonElement element = parser.parse(apiRequestBodyAsJson);
+ fixedDepositAccountInterestCalculationServiceImpl = new
FixedDepositAccountInterestCalculationServiceImpl(
+ new DepositAccountDataValidator(new FromJsonHelper(), null),
new FromJsonHelper());
+
+ assertThrows(PlatformApiDataValidationException.class, () ->
fixedDepositAccountInterestCalculationServiceImpl
+ .calculateInterest(new JsonQuery(apiRequestBodyAsJson,
element, new FromJsonHelper())));
+ }
+
+ @Test
+ public void
testFixedDepositInterestCalculationWithWrongCompoundingPeriod2() {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("principalAmount", 100);
+ jsonObject.addProperty("annualInterestRate", 5);
+ jsonObject.addProperty("tenureInMonths", 15);
+ jsonObject.addProperty("interestPostingPeriodInMonths", 3);
+ jsonObject.addProperty("interestCompoundingPeriodInMonths", 6);
+ JsonParser parser = new JsonParser();
+ String apiRequestBodyAsJson = jsonObject.toString();
+ JsonElement element = parser.parse(apiRequestBodyAsJson);
+ fixedDepositAccountInterestCalculationServiceImpl = new
FixedDepositAccountInterestCalculationServiceImpl(
+ new DepositAccountDataValidator(new FromJsonHelper(), null),
new FromJsonHelper());
+
+ assertThrows(PlatformApiDataValidationException.class, () ->
fixedDepositAccountInterestCalculationServiceImpl
+ .calculateInterest(new JsonQuery(apiRequestBodyAsJson,
element, new FromJsonHelper())));
+ }
+
+ @Test
+ public void testFixedDepositInterestCalculationWithValidInput() {
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("principalAmount", 10000);
+ jsonObject.addProperty("annualInterestRate", 5);
+ jsonObject.addProperty("tenureInMonths", 12);
+ jsonObject.addProperty("interestPostingPeriodInMonths", 3);
+ jsonObject.addProperty("interestCompoundingPeriodInMonths", 1);
+ JsonParser parser = new JsonParser();
+ String apiRequestBodyAsJson = jsonObject.toString();
+ JsonElement element = parser.parse(apiRequestBodyAsJson);
+ fixedDepositAccountInterestCalculationServiceImpl = new
FixedDepositAccountInterestCalculationServiceImpl(
+ new DepositAccountDataValidator(new FromJsonHelper(), null),
new FromJsonHelper());
+ Double expectedResult = 10511.61897;
Review Comment:
Please dont work with doubles! Use BigDecimal!
--
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]