Skip to content

FINERACT-2539: Add unit tests for MathUtil#5628

Open
devi-pathak2263 wants to merge 2 commits intoapache:developfrom
devi-pathak2263:add-mathutil-tests
Open

FINERACT-2539: Add unit tests for MathUtil#5628
devi-pathak2263 wants to merge 2 commits intoapache:developfrom
devi-pathak2263:add-mathutil-tests

Conversation

@devi-pathak2263
Copy link

##Description

This PR adds unit tests for the MathUtil utility class located in fineract-core.

The MathUtil class contains several helper methods used across the platform for null handling, arithmetic operations, numeric comparisons, and BigDecimal utilities. These utilities are frequently used by different modules and therefore benefit from dedicated test coverage.

The added tests verify the behavior of multiple helper methods including:

  • Null handling utilities (nullToDefault, nullToZero, zeroToNull)
  • Numeric comparison helpers (isGreaterThanZero, isLessThanZero)
  • Arithmetic helpers (add, subtract, abs)
  • BigDecimal helper methods
  • Percentage calculation (percentageOf)
  • Formatting utilities such as stripTrailingZeros

The tests include validation of typical scenarios as well as important edge cases such as:

  • null inputs
  • zero values
  • negative values
  • BigDecimal precision handling

These tests improve reliability and increase the overall test coverage of shared mathematical utilities used throughout the system.

JIRA: https://issues.apache.org/jira/browse/FINERACT-2539

Testing

Executed locally:

./gradlew spotlessApply
./gradlew :fineract-core:test

Checklist

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

  • Write the commit message as per our guidelines
  • 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 our 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
  • This PR must not be a "code dump". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.

Your assigned reviewer(s) will follow our guidelines for code reviews.

Add comprehensive unit tests for the StreamResponseUtil utility class.

Tests cover:
- ok(StreamResponseData) response creation
- ok(AsyncResponse, StreamResponseData) asynchronous response handling
- Content-Disposition header generation
- StreamingOutput functionality
- Async response execution

These tests improve test coverage and help ensure correct behavior of response streaming utilities.
@devi-pathak2263 devi-pathak2263 changed the title Add mathutil tests FINERACT-2539: Add mathutil tests Mar 16, 2026
@devi-pathak2263 devi-pathak2263 changed the title FINERACT-2539: Add mathutil tests FINERACT-2539: Add unit tests for MathUtil Mar 16, 2026
@@ -0,0 +1,143 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is MathUtil needed? There are already functions on BigInteger/BigDecimal for add/subtract/mulitply/divide...

Copy link
Author

Choose a reason for hiding this comment

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

This PR only adds unit tests for the existing MathUtil utility class. The implementation of MathUtil was already present in the codebase and is currently used in several parts of the project.

The goal of this PR is to improve test coverage and ensure the correctness of the helper methods already provided by MathUtil, especially around null handling, comparison helpers, and convenience wrappers used across the platform.

No changes were made to the implementation itself.

@adamsaghy
Copy link
Contributor

@devi-pathak2263 Can you please:

Set the commit email address to match with your github account email address?
Set GPG signature for commit?

@adamsaghy
Copy link
Contributor

/home/runner/work/fineract/fineract/fineract-core/src/test/java/org/apache/fineract/infrastructure/core/service/IpAddressUtilsTest.java:21: error: [WildcardImport] Wildcard imports, static or otherwise, should not be used
import static org.junit.jupiter.api.Assertions.*;

@devi-pathak2263
Copy link
Author

@devi-pathak2263 Can you please:

Set the commit email address to match with your github account email address? Set GPG signature for commit?

I have updated the commit author email to match my GitHub account and added a signed commit using SSH.

@adamsaghy
Copy link
Contributor

@devi-pathak2263 You need to amend the original commit to take effect, but before you do that, please use GPG instead of SSH. SSH would require to maintain allowedSigners but we dont want that.

@devi-pathak2263
Copy link
Author

  • Updated the test imports to avoid wildcard usage and comply with project conventions.

  • Amended the commit to use a GPG-signed commit (instead of SSH) and aligned the author email with my GitHub account.

Please let me know if anything else needs adjustment.

Add comprehensive unit tests for MathUtil covering core behaviors
including null handling, arithmetic operations, comparison helpers,
BigDecimal operations, percentage calculations, and formatting helpers.

The tests verify correct handling of:
- null and default value behavior
- negative and zero values
- arithmetic operations (add, subtract, abs)
- BigDecimal utilities
- percentage calculations
- trailing zero normalization

These tests improve reliability and increase test coverage for
shared mathematical utilities used across the platform.
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.

3 participants