Skip to content
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

FINERACT-2156: Confirm existance of elements before accessing them #4202

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

wkigenyi
Copy link
Contributor

@wkigenyi wkigenyi commented Dec 1, 2024

Description

Describe the changes made and why they were made.

Ignore if these details are present on the associated Apache Fineract JIRA ticket.

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per https://github.com/apache/fineract/#pull-requests

  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.

  • Create/update unit or integration tests for verifying the changes made.

  • Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.

  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes

  • Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)

FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.

@@ -0,0 +1,1068 @@
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this.

@@ -0,0 +1,1093 @@
#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please kindly remove the log files!

@wkigenyi wkigenyi marked this pull request as ready for review December 31, 2024 06:58
@wkigenyi
Copy link
Contributor Author

wkigenyi commented Jan 1, 2025

@adamsaghy this is now ready for review

@@ -1594,12 +1594,19 @@ public void validateAccountBalanceDoesNotBecomeNegative(final String transaction
public void validateAccountBalanceDoesNotViolateOverdraft(final List<SavingsAccountTransaction> savingsAccountTransaction,
final BigDecimal amountPaid) {
if (savingsAccountTransaction != null) {
SavingsAccountTransaction savingsAccountTransactionFirst = savingsAccountTransaction.get(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind to simplify the logic a little bit further?

You can merge the savingsAccountTransaction != null and savingsAccountTransaction.size() > 0 condition together and if they are TRUE take the running balance of the first element otherwise it is BigDecimal.ZERO (if there are no any transaction the running balance must be 0).
After you can deduct the amountPaid from the above balance and if the balance is negative and allowOverdraft is FALSE then InsufficientAccountBalanceException to be thrown.

I believe it would be easier to read and cover better the requirements!

Also kindly asking you to write a test (it can be unit tests), which covers the following situations:

  • savingsAccountTransaction is empty and amountPaid is positive and allowOverdraft = true -> No exception!
  • savingsAccountTransaction is empty and amountPaid is positive and allowOverdraft = false -> Exception to be thrown!
  • savingsAccountTransaction is not empty and amountPaid is positive and amountPaid is higher than the running balance of the 1st transaciton and allowOverdraft = true -> No exception!
  • savingsAccountTransaction is not empty and amountPaid is positive and amountPaid is lower than the running balance of the 1st transaction and allowOverdraft = false -> Exception to be thrown!
  • savingsAccountTransaction is not empty and amountPaid is positive and amountPaid is equal with the running balance of the 1st transaction and allowOverdraft = false -> No exception!

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wkigenyi Kindly see my review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants