Skip to content

Commit

Permalink
Update BalanceData to use BigDecimal instead of double
Browse files Browse the repository at this point in the history
  • Loading branch information
ericgrandt committed Mar 3, 2024
1 parent 1149ed4 commit 85bfd32
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ public BigDecimal getBalance(UUID accountId, int currencyId) throws SQLException
return BigDecimal.ZERO;
}

// TODO: Remove in favor of the BigDecimal updateBalance below
public int updateBalance(UUID accountId, int currencyId, double balance) throws SQLException {
String updateBalanceQuery = "UPDATE te_balance SET balance = ? WHERE account_id = ? AND currency_id = ?";

try (
Connection conn = database.getDataSource().getConnection();
PreparedStatement stmt = conn.prepareStatement(updateBalanceQuery)
) {
stmt.setBigDecimal(1, BigDecimal.valueOf(balance));
stmt.setString(2, accountId.toString());
stmt.setInt(3, currencyId);

return stmt.executeUpdate();
}
}

public int updateBalance(UUID accountId, int currencyId, BigDecimal balance) throws SQLException {
String updateBalanceQuery = "UPDATE te_balance SET balance = ? WHERE account_id = ? AND currency_id = ?";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void updateBalance_WithBalanceUpdated_ShouldReturnOne() throws SQLExcepti
BalanceData sut = new BalanceData(databaseMock);

// Act
int actual = sut.updateBalance(UUID.randomUUID(), 1, 100);
int actual = sut.updateBalance(UUID.randomUUID(), 1, BigDecimal.valueOf(100));
int expected = 1;

// Assert
Expand All @@ -109,7 +109,7 @@ public void updateBalance_WithNoBalanceUpdated_ShouldReturnZero() throws SQLExce
BalanceData sut = new BalanceData(databaseMock);

// Act
int actual = sut.updateBalance(UUID.randomUUID(), 1, 100);
int actual = sut.updateBalance(UUID.randomUUID(), 1, BigDecimal.valueOf(100));
int expected = 0;

// Assert
Expand Down Expand Up @@ -159,7 +159,7 @@ public void updateBalance_ShouldUpdateBalance() throws SQLException {
BalanceData sut = new BalanceData(databaseMock);

// Act
int actual = sut.updateBalance(accountId, currencyId, 100);
int actual = sut.updateBalance(accountId, currencyId, BigDecimal.valueOf(100));
int expected = 1;

BalanceDto actualBalanceDto = TestUtils.getBalanceForAccountId(accountId, currencyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class EconomyImpl implements EconomyService {

private final Currency currency;

// TODO: Replace data params with CommonEconomy
public EconomyImpl(
final SpongeWrapper spongeWrapper,
final CurrencyDto currencyDto,
Expand Down

0 comments on commit 85bfd32

Please sign in to comment.