You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@johnzon.apache.org by st...@apache.org on 2026/07/14 21:06:25 UTC
(johnzon) branch master updated: add all the other method calls ot JsonNumberImpl
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/johnzon.git
The following commit(s) were added to refs/heads/master by this push:
new 4fd60751 add all the other method calls ot JsonNumberImpl
4fd60751 is described below
commit 4fd60751eb25a03a77ebeef561645fcc0d03deab
Author: Mark Struberg <st...@apache.org>
AuthorDate: Tue Jul 14 23:05:52 2026 +0200
add all the other method calls ot JsonNumberImpl
We now have full coverage of that class.
---
.../apache/johnzon/core/JsonReaderImplTest.java | 42 ++++++++++++++--------
1 file changed, 27 insertions(+), 15 deletions(-)
diff --git a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java
index a84c37f4..0f4eeb5a 100644
--- a/johnzon-core/src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java
+++ b/johnzon-core/src/test/java/org/apache/johnzon/core/JsonReaderImplTest.java
@@ -31,11 +31,13 @@ import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
+import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.function.Supplier;
import jakarta.json.Json;
import jakarta.json.JsonArray;
@@ -161,45 +163,55 @@ public class JsonReaderImplTest {
@Test
public void parseBigIntegerFailOnTooLongExponent() {
- String json = "1e150000000";
+ String json = "1e1500000000";
JsonValue jsonValue = Json.createReader(new StringReader(json)).readValue();
String newJson = jsonValue.toString();
- assertEquals("1E+150000000", newJson);
+ assertEquals("1E+1500000000", newJson);
assertTrue(jsonValue instanceof JsonNumber);
+ final JsonNumber jsonNumber = (JsonNumber) jsonValue;
+
try {
- ((JsonNumber) jsonValue).bigIntegerValue();
+ jsonNumber.bigIntegerValue();
fail();
} catch (ArithmeticException ae) {
// all fine
}
try {
- ((JsonNumber) jsonValue).bigIntegerValueExact();
+ jsonNumber.bigIntegerValueExact();
fail();
} catch (ArithmeticException ae) {
// all fine
}
- final long longVal = ((JsonNumber) jsonValue).longValue();
- final int intVal = ((JsonNumber) jsonValue).intValue();
- final double doubleVal = ((JsonNumber) jsonValue).doubleValue();
+ // we don't need to assert the return values, it's just to trigger timeouts
+ final long longVal = jsonNumber.longValue();
+ final int intVal = jsonNumber.intValue();
+ final double doubleVal = jsonNumber.doubleValue();
+ jsonNumber.numberValue();
+ jsonNumber.isIntegral();
+ jsonNumber.hashCode();
- try {
- final long lve = ((JsonNumber) jsonValue).longValueExact();
- fail();
- } catch (ArithmeticException ae) {
- // all fine
- }
+ assertArithmeticException(()-> jsonNumber.equals(new JsonNumberImpl(BigDecimal.valueOf(1, 1000000000),
+ ((JsonProviderImpl)JsonProviderImpl.provider())::checkBigDecimalScale)));
+ assertArithmeticException(()-> jsonNumber.bigDecimalValue().longValueExact());
+
+ assertArithmeticException(()-> jsonNumber.longValueExact());
+ assertArithmeticException(()-> jsonNumber.intValueExact());
+
+
+ }
+
+ private void assertArithmeticException(Supplier<?> supplier) {
try {
- final long lve = ((JsonNumber) jsonValue).intValueExact();
+ supplier.get();
fail();
} catch (ArithmeticException ae) {
// all fine
}
-
}
/**