Skip to content

Fix: Change Balance fields from Double to BigDecimal#35

Merged
Fivell merged 3 commits intomainfrom
fix/balance-string-type
Mar 11, 2026
Merged

Fix: Change Balance fields from Double to BigDecimal#35
Fivell merged 3 commits intomainfrom
fix/balance-string-type

Conversation

@Fivell
Copy link
Member

@Fivell Fivell commented Mar 10, 2026

Summary

  • Changed totalBalance, balance, and credit fields from Double to BigDecimal
  • Ensures precise monetary arithmetic without floating-point errors
  • Updated tests to use isEqualByComparingTo for BigDecimal comparison

Test plan

  • BalanceTest verifies all three fields parse correctly as BigDecimal
  • All tests pass

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Balance resource to represent monetary amounts using BigDecimal instead of Double, and adjusts the corresponding test assertions to compare BigDecimal values correctly.

Changes:

  • Changed totalBalance, balance, and credit in Balance from Double to BigDecimal
  • Updated BalanceTest assertions to use isEqualByComparingTo with BigDecimal expectations

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/com/didww/sdk/resource/Balance.java Switches balance-related monetary fields and getters from Double to BigDecimal.
src/test/java/com/didww/sdk/resource/BalanceTest.java Updates assertions to compare BigDecimal values rather than floating-point values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +10
import static org.assertj.core.api.Assertions.assertThat;
import static com.github.tomakehurst.wiremock.client.WireMock.*;

import java.math.BigDecimal;

Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Import ordering is inconsistent with the rest of the test suite (e.g., AddressTest groups non-static imports first, then static imports). java.math.BigDecimal should be placed with the other non-static imports above the static imports to match the project’s import style / avoid checkstyle failures.

Suggested change
import static org.assertj.core.api.Assertions.assertThat;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import java.math.BigDecimal;
import java.math.BigDecimal;
import static org.assertj.core.api.Assertions.assertThat;
import static com.github.tomakehurst.wiremock.client.WireMock.*;

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 15 to +16
@JsonProperty("total_balance")
private Double totalBalance;
private BigDecimal totalBalance;
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Changing totalBalance/balance/credit from Double to BigDecimal (and the corresponding getter return types) is a breaking public API change for SDK consumers. Please ensure any in-repo callers (e.g., examples/README snippets) are updated accordingly, and consider providing a backwards-compatible path (e.g., deprecated Double-returning accessors or a documented major version bump/release note) so downstream users aren’t surprised by compilation failures.

Copilot uses AI. Check for mistakes.
import com.didww.sdk.repository.ApiResponse;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Import grouping is inconsistent with other tests in this package (they don’t separate regular imports from static imports with an extra blank line). Consider removing the blank line after import java.math.BigDecimal; to keep import formatting consistent.

Suggested change

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

public Double getCredit() {
public BigDecimal getCredit() {
return credit;
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Changing the public getter return types from Double to BigDecimal is a breaking API change for SDK consumers (compile-time). If backwards compatibility is required, consider keeping the Double getters (deprecated) or adding alternate getters (e.g., getTotalBalanceAsDouble()) and documenting the migration/release versioning accordingly.

Suggested change
}
}
@Deprecated
public Double getTotalBalanceAsDouble() {
return totalBalance != null ? totalBalance.doubleValue() : null;
}
@Deprecated
public Double getBalanceAsDouble() {
return balance != null ? balance.doubleValue() : null;
}
@Deprecated
public Double getCreditAsDouble() {
return credit != null ? credit.doubleValue() : null;
}

Copilot uses AI. Check for mistakes.
@Fivell Fivell force-pushed the fix/balance-string-type branch from 4504fc9 to b5637f3 Compare March 11, 2026 16:22
@sonarqubecloud
Copy link

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +24 to +28
public BigDecimal getTotalBalance() {
return totalBalance;
}

public Double getBalance() {
public BigDecimal getBalance() {
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

Changing these getters from Double to BigDecimal is a source/binary breaking change for SDK consumers (method signature change). If the library intends to remain backward compatible, consider keeping the Double getters (deprecated) and adding new BigDecimal-named accessors, or ensure the release/versioning/docs explicitly treat this as a breaking change.

Copilot uses AI. Check for mistakes.
@Fivell Fivell merged commit b1a48f5 into main Mar 11, 2026
9 checks passed
@Fivell Fivell deleted the fix/balance-string-type branch March 11, 2026 16:44
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