Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sappenin committed Aug 22, 2024
1 parent a1a20e2 commit 374d7d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ private static void assertXrpIsValid(String amount) {
if (!value.equals(BigDecimal.ZERO)) {
if (value.signum() < 0) { // `value` is negative
if (value.compareTo(MAX_NEGATIVE_XRP) > 0 || value.compareTo(MIN_DROPS) < 0) {
throw new IllegalArgumentException(amount + " is an illegal amount");
throw new IllegalArgumentException(String.format("%s is an illegal amount", amount));
}
} else { // `value` is positive
if (value.compareTo(MIN_XRP) < 0 || value.compareTo(MAX_DROPS) > 0) {
throw new IllegalArgumentException(amount + " is an illegal amount");
throw new IllegalArgumentException(String.format("%s is an illegal amount", amount));
}
}
}
Expand Down Expand Up @@ -181,9 +181,7 @@ public AmountType fromJson(JsonNode value) throws JsonProcessingException {
result.append(currency);
result.append(issuer);

return new

AmountType(result);
return new AmountType(result);
}

private UnsignedByteArray getAmountBytes(BigDecimal number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -124,9 +125,19 @@ void encodeDecodePositiveXrpAmount() throws JsonProcessingException {
@Test
void encodeOutOfBounds() {
// Positive
assertThrows(IllegalArgumentException.class, () -> codec.fromJson("416345785D8A0001"));
{
IllegalArgumentException thrownError = assertThrows(
IllegalArgumentException.class, () -> codec.fromJson("100000000000000001")
);
assertThat(thrownError.getMessage()).isEqualTo("100000000000000001 is an illegal amount");
}
// Negative
assertThrows(IllegalArgumentException.class, () -> codec.fromJson("-416345785D8A0001"));
{
IllegalArgumentException thrownError = assertThrows(
IllegalArgumentException.class, () -> codec.fromJson("-100000000000000001")
);
assertThat(thrownError.getMessage()).isEqualTo("-100000000000000001 is an illegal amount");
}
}

@Test
Expand Down

0 comments on commit 374d7d6

Please sign in to comment.