Skip to content

Commit

Permalink
Review notes applied.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus committed Apr 26, 2023
1 parent 22f3263 commit de1b1f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ protected void tearDown() {
// Test BigDecimal max source characters array length using length equal to system property limit of 500.
// Parsing shall pass and return value equal to source String.
public void testLargeBigDecimalBellowLimit() {
String sourceValue = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706"
+ "7982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381"
+ "9644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412"
+ "7372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160"
+ "9433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949";
JsonReader reader = Json.createReader(new StringReader(sourceValue));
JsonNumber check = Json.createValue(new BigDecimal(sourceValue));
JsonReader reader = Json.createReader(new StringReader(JsonNumberTest.Π_500));
JsonNumber check = Json.createValue(new BigDecimal(JsonNumberTest.Π_500));
JsonValue value = reader.readValue();
assertEquals(value.getValueType(), JsonValue.ValueType.NUMBER);
assertEquals(value, check);
Expand All @@ -63,13 +58,7 @@ public void testLargeBigDecimalBellowLimit() {
// Test BigDecimal max source characters array length using length above system property limit of 500.
// Parsing shall pass and return value equal to source String.
public void testLargeBigDecimalAboveLimit() {
String sourceValue = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706"
+ "7982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381"
+ "9644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412"
+ "7372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160"
+ "9433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949"
+ "1";
JsonReader reader = Json.createReader(new StringReader(sourceValue));
JsonReader reader = Json.createReader(new StringReader(JsonNumberTest.Π_501));
try {
reader.readValue();
fail("No exception was thrown from BigDecimal parsing with source characters array length over limit");
Expand Down
72 changes: 32 additions & 40 deletions impl/src/test/java/org/eclipse/parsson/tests/JsonNumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@
* @author Jitendra Kotamraju
*/
public class JsonNumberTest extends TestCase {

// π as JsonNumber with 500 source characters
static final String Π_500
= "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706"
+ "7982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381"
+ "9644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412"
+ "7372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160"
+ "9433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949";

// π as JsonNumber with 501 source characters
static final String Π_501 = Π_500 + "1";

// π as JsonNumber with 1100 source characters
private static final String Π_1100
= Π_500
+ "1298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051"
+ "3200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892"
+ "3542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318"
+ "5950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473"
+ "0359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019"
+ "8938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131";

// π as JsonNumber with 1100 source characters
private static final String Π_1101
= Π_1100 + "5";

public JsonNumberTest(String testName) {
super(testName);
}
Expand Down Expand Up @@ -292,19 +318,8 @@ public void testConfigBigIntegerScaleAboveLimit() {
// Test BigDecimal max source characters array length using length equal to default limit of 1100.
// Parsing shall pass and return value equal to source String.
public void testLargeBigDecimalBellowLimit() {
String sourceValue = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706"
+ "7982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381"
+ "9644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412"
+ "7372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160"
+ "9433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949"
+ "1298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051"
+ "3200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892"
+ "3542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318"
+ "5950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473"
+ "0359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019"
+ "8938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131";
JsonReader reader = Json.createReader(new StringReader(sourceValue));
JsonNumber check = Json.createValue(new BigDecimal(sourceValue));
JsonReader reader = Json.createReader(new StringReader(Π_1100));
JsonNumber check = Json.createValue(new BigDecimal(Π_1100));
JsonValue value = reader.readValue();
assertEquals(value.getValueType(), JsonValue.ValueType.NUMBER);
assertEquals(value, check);
Expand All @@ -313,19 +328,7 @@ public void testLargeBigDecimalBellowLimit() {
// Test BigDecimal max source characters array length using length above default limit of 1100.
// Parsing shall throw specific UnsupportedOperationException exception.
public void testLargeBigDecimalAboveLimit() {
String sourceValue = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706"
+ "7982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381"
+ "9644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412"
+ "7372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160"
+ "9433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949"
+ "1298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051"
+ "3200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892"
+ "3542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318"
+ "5950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473"
+ "0359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019"
+ "8938095257201065485863278865936153381827968230301952035301852968995773622599413891249721775283479131"
+ "5";
JsonReader reader = Json.createReader(new StringReader(sourceValue));
JsonReader reader = Json.createReader(new StringReader(Π_1101));
try {
reader.readValue();
fail("No exception was thrown from BigDecimal parsing with source characters array length over limit");
Expand All @@ -340,14 +343,9 @@ public void testLargeBigDecimalAboveLimit() {
// Test BigDecimal max source characters array length using length equal to custom limit of 500.
// Parsing shall pass and return value equal to source String.
public void testLargeBigDecimalBellowCustomLimit() {
String sourceValue = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706"
+ "7982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381"
+ "9644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412"
+ "7372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160"
+ "9433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949";
Map<String, ?> config = Map.of(JsonConfig.MAX_BIGDECIMAL_LEN, "500");
JsonReader reader = Json.createReaderFactory(config).createReader(new StringReader(sourceValue));
JsonNumber check = Json.createValue(new BigDecimal(sourceValue));
JsonReader reader = Json.createReaderFactory(config).createReader(new StringReader(Π_500));
JsonNumber check = Json.createValue(new BigDecimal(Π_500));
JsonValue value = reader.readValue();
assertEquals(value.getValueType(), JsonValue.ValueType.NUMBER);
assertEquals(value, check);
Expand All @@ -356,14 +354,8 @@ public void testLargeBigDecimalBellowCustomLimit() {
// Test BigDecimal max source characters array length using length equal to custom limit of 200.
// Parsing shall pass and return value equal to source String.
public void testLargeBigDecimalAboveCustomLimit() {
String sourceValue = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706"
+ "7982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381"
+ "9644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412"
+ "7372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160"
+ "9433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949"
+ "1";
Map<String, ?> config = Map.of(JsonConfig.MAX_BIGDECIMAL_LEN, "500");
JsonReader reader = Json.createReaderFactory(config).createReader(new StringReader(sourceValue));
JsonReader reader = Json.createReaderFactory(config).createReader(new StringReader(Π_501));
try {
reader.readValue();
fail("No exception was thrown from BigDecimal parsing with source characters array length over limit");
Expand Down

0 comments on commit de1b1f0

Please sign in to comment.