From fefd616d73c063de3ffb4749e6b46b363eea3e93 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 9 Aug 2017 21:51:46 -0400 Subject: [PATCH 1/6] Unit tests for JSONTokener --- build.gradle | 1 + .../java/org/json/junit/JSONObjectTest.java | 170 ++++++++++++++++++ 2 files changed, 171 insertions(+) diff --git a/build.gradle b/build.gradle index 43656ae..53fbdb3 100644 --- a/build.gradle +++ b/build.gradle @@ -22,6 +22,7 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.+' testCompile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.1.0' testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5' + testCompile group: 'slf4j.org', name: 'slf4j', version: '1.6.1' // Uncomment if you are testing against a JSON-Java release // testCompile 'org.json:json:20160212' // Uncomment if you have copied a local JSON-Java jar file into this project diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 1231ec9..35cf493 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -1976,6 +1976,176 @@ public void jsonObjectParsingErrors() { } catch (JSONException e) { assertTrue("", true); } + try { + // test exception message when including a duplicate key (level 0) + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr03\":\"value-04\"\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); + } catch (JSONException e) { + assertEquals("Expecting an expection message", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", + e.getMessage()); + } + try { + // test exception message when including a duplicate key (level 0) holding an object + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr03\": {" + +" \"attr04-01\":\"value-04-01\",n" + +" \"attr04-02\":\"value-04-02\",n" + +" \"attr04-03\":\"value-04-03\"n" + + " }\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); + } catch (JSONException e) { + assertEquals("Expecting an expection message", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", + e.getMessage()); + } + try { + // test exception message when including a duplicate key (level 0) holding an array + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr03\": [\n" + +" {" + +" \"attr04-01\":\"value-04-01\",n" + +" \"attr04-02\":\"value-04-02\",n" + +" \"attr04-03\":\"value-04-03\"n" + +" }\n" + + " ]\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); + } catch (JSONException e) { + assertEquals("Expecting an expection message", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", + e.getMessage()); + } + try { + // test exception message when including a duplicate key (level 1) + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr04\": {\n" + +" \"attr04-01\":\"value04-01\",\n" + +" \"attr04-02\":\"value04-02\",\n" + +" \"attr04-03\":\"value04-03\",\n" + +" \"attr04-03\":\"value04-04\"\n" + + " }\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); + } catch (JSONException e) { + assertEquals("Expecting an expection message", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + e.getMessage()); + } + try { + // test exception message when including a duplicate key (level 1) holding an object + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr04\": {\n" + +" \"attr04-01\":\"value04-01\",\n" + +" \"attr04-02\":\"value04-02\",\n" + +" \"attr04-03\":\"value04-03\",\n" + +" \"attr04-03\": {\n" + +" \"attr04-04-01\":\"value04-04-01\",\n" + +" \"attr04-04-02\":\"value04-04-02\",\n" + +" \"attr04-04-03\":\"value04-04-03\",\n" + +" }\n" + +" }\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); + } catch (JSONException e) { + assertEquals("Expecting an expection message", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + e.getMessage()); + } + try { + // test exception message when including a duplicate key (level 1) holding an array + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr04\": {\n" + +" \"attr04-01\":\"value04-01\",\n" + +" \"attr04-02\":\"value04-02\",\n" + +" \"attr04-03\":\"value04-03\",\n" + +" \"attr04-03\": [\n" + +" {\n" + +" \"attr04-04-01\":\"value04-04-01\",\n" + +" \"attr04-04-02\":\"value04-04-02\",\n" + +" \"attr04-04-03\":\"value04-04-03\",\n" + +" }\n" + +" ]\n" + +" }\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); + } catch (JSONException e) { + assertEquals("Expecting an expection message", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + e.getMessage()); + } + try { + // test exception message when including a duplicate key in object (level 0) within an array + String str = "[\n" + +" {\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\"\n" + +" },\n" + +" {\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr01\":\"value-02\"\n" + +" }\n" + + "]"; + new JSONArray(str); + fail("Expected an exception"); + } catch (JSONException e) { + assertEquals("Expecting an expection message", + "Duplicate key \"attr01\" at 124 [character 17 line 8]", + e.getMessage()); + } + try { + // test exception message when including a duplicate key in object (level 1) within an array + String str = "[\n" + +" {\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\": {\n" + +" \"attr02-01\":\"value-02-01\",\n" + +" \"attr02-02\":\"value-02-02\"\n" + +" }\n" + +" },\n" + +" {\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\": {\n" + +" \"attr02-01\":\"value-02-01\",\n" + +" \"attr02-01\":\"value-02-02\"\n" + +" }\n" + +" }\n" + + "]"; + System.out.println(str); + new JSONArray(str); + fail("Expected an exception"); + } catch (JSONException e) { + assertEquals("Expecting an expection message", + "Duplicate key \"attr02-01\" at 269 [character 24 line 13]", + e.getMessage()); + } } /** From 1acb18091a7006fd8a113c474a912cfd4cc6a375 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 9 Aug 2017 21:57:10 -0400 Subject: [PATCH 2/6] Remove System.out.println --- src/test/java/org/json/junit/JSONObjectTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 35cf493..6470ebb 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -2138,7 +2138,6 @@ public void jsonObjectParsingErrors() { +" }\n" +" }\n" + "]"; - System.out.println(str); new JSONArray(str); fail("Expected an exception"); } catch (JSONException e) { From df466db7b9630e689813dd82de5f512ca0713273 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 9 Aug 2017 21:59:08 -0400 Subject: [PATCH 3/6] Replacing tabs with 4 spaces --- .../java/org/json/junit/JSONObjectTest.java | 290 +++++++++--------- 1 file changed, 145 insertions(+), 145 deletions(-) diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 6470ebb..2dcebe4 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -1977,173 +1977,173 @@ public void jsonObjectParsingErrors() { assertTrue("", true); } try { - // test exception message when including a duplicate key (level 0) - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr03\":\"value-04\"\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); + // test exception message when including a duplicate key (level 0) + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr03\":\"value-04\"\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", - e.getMessage()); + assertEquals("Expecting an expection message", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", + e.getMessage()); } try { - // test exception message when including a duplicate key (level 0) holding an object - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr03\": {" - +" \"attr04-01\":\"value-04-01\",n" - +" \"attr04-02\":\"value-04-02\",n" - +" \"attr04-03\":\"value-04-03\"n" - + " }\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); + // test exception message when including a duplicate key (level 0) holding an object + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr03\": {" + +" \"attr04-01\":\"value-04-01\",n" + +" \"attr04-02\":\"value-04-02\",n" + +" \"attr04-03\":\"value-04-03\"n" + + " }\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", - e.getMessage()); + assertEquals("Expecting an expection message", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", + e.getMessage()); } try { - // test exception message when including a duplicate key (level 0) holding an array - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr03\": [\n" - +" {" - +" \"attr04-01\":\"value-04-01\",n" - +" \"attr04-02\":\"value-04-02\",n" - +" \"attr04-03\":\"value-04-03\"n" - +" }\n" - + " ]\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); + // test exception message when including a duplicate key (level 0) holding an array + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr03\": [\n" + +" {" + +" \"attr04-01\":\"value-04-01\",n" + +" \"attr04-02\":\"value-04-02\",n" + +" \"attr04-03\":\"value-04-03\"n" + +" }\n" + + " ]\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", - e.getMessage()); + assertEquals("Expecting an expection message", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", + e.getMessage()); } try { - // test exception message when including a duplicate key (level 1) - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr04\": {\n" - +" \"attr04-01\":\"value04-01\",\n" - +" \"attr04-02\":\"value04-02\",\n" - +" \"attr04-03\":\"value04-03\",\n" - +" \"attr04-03\":\"value04-04\"\n" - + " }\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); + // test exception message when including a duplicate key (level 1) + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr04\": {\n" + +" \"attr04-01\":\"value04-01\",\n" + +" \"attr04-02\":\"value04-02\",\n" + +" \"attr04-03\":\"value04-03\",\n" + +" \"attr04-03\":\"value04-04\"\n" + + " }\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", - e.getMessage()); + assertEquals("Expecting an expection message", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + e.getMessage()); } try { - // test exception message when including a duplicate key (level 1) holding an object - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr04\": {\n" - +" \"attr04-01\":\"value04-01\",\n" - +" \"attr04-02\":\"value04-02\",\n" - +" \"attr04-03\":\"value04-03\",\n" - +" \"attr04-03\": {\n" - +" \"attr04-04-01\":\"value04-04-01\",\n" - +" \"attr04-04-02\":\"value04-04-02\",\n" - +" \"attr04-04-03\":\"value04-04-03\",\n" - +" }\n" - +" }\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); + // test exception message when including a duplicate key (level 1) holding an object + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr04\": {\n" + +" \"attr04-01\":\"value04-01\",\n" + +" \"attr04-02\":\"value04-02\",\n" + +" \"attr04-03\":\"value04-03\",\n" + +" \"attr04-03\": {\n" + +" \"attr04-04-01\":\"value04-04-01\",\n" + +" \"attr04-04-02\":\"value04-04-02\",\n" + +" \"attr04-04-03\":\"value04-04-03\",\n" + +" }\n" + +" }\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", - e.getMessage()); + assertEquals("Expecting an expection message", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + e.getMessage()); } try { - // test exception message when including a duplicate key (level 1) holding an array - String str = "{\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\",\n" - +" \"attr03\":\"value-03\",\n" - +" \"attr04\": {\n" - +" \"attr04-01\":\"value04-01\",\n" - +" \"attr04-02\":\"value04-02\",\n" - +" \"attr04-03\":\"value04-03\",\n" - +" \"attr04-03\": [\n" - +" {\n" - +" \"attr04-04-01\":\"value04-04-01\",\n" - +" \"attr04-04-02\":\"value04-04-02\",\n" - +" \"attr04-04-03\":\"value04-04-03\",\n" - +" }\n" - +" ]\n" - +" }\n" - + "}"; - new JSONObject(str); - fail("Expected an exception"); + // test exception message when including a duplicate key (level 1) holding an array + String str = "{\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\",\n" + +" \"attr03\":\"value-03\",\n" + +" \"attr04\": {\n" + +" \"attr04-01\":\"value04-01\",\n" + +" \"attr04-02\":\"value04-02\",\n" + +" \"attr04-03\":\"value04-03\",\n" + +" \"attr04-03\": [\n" + +" {\n" + +" \"attr04-04-01\":\"value04-04-01\",\n" + +" \"attr04-04-02\":\"value04-04-02\",\n" + +" \"attr04-04-03\":\"value04-04-03\",\n" + +" }\n" + +" ]\n" + +" }\n" + + "}"; + new JSONObject(str); + fail("Expected an exception"); } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", - e.getMessage()); + assertEquals("Expecting an expection message", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + e.getMessage()); } try { - // test exception message when including a duplicate key in object (level 0) within an array - String str = "[\n" - +" {\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\":\"value-02\"\n" - +" },\n" - +" {\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr01\":\"value-02\"\n" - +" }\n" - + "]"; - new JSONArray(str); - fail("Expected an exception"); + // test exception message when including a duplicate key in object (level 0) within an array + String str = "[\n" + +" {\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\":\"value-02\"\n" + +" },\n" + +" {\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr01\":\"value-02\"\n" + +" }\n" + + "]"; + new JSONArray(str); + fail("Expected an exception"); } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr01\" at 124 [character 17 line 8]", - e.getMessage()); + assertEquals("Expecting an expection message", + "Duplicate key \"attr01\" at 124 [character 17 line 8]", + e.getMessage()); } try { - // test exception message when including a duplicate key in object (level 1) within an array - String str = "[\n" - +" {\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\": {\n" - +" \"attr02-01\":\"value-02-01\",\n" - +" \"attr02-02\":\"value-02-02\"\n" - +" }\n" - +" },\n" - +" {\n" - +" \"attr01\":\"value-01\",\n" - +" \"attr02\": {\n" - +" \"attr02-01\":\"value-02-01\",\n" - +" \"attr02-01\":\"value-02-02\"\n" - +" }\n" - +" }\n" - + "]"; - new JSONArray(str); - fail("Expected an exception"); + // test exception message when including a duplicate key in object (level 1) within an array + String str = "[\n" + +" {\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\": {\n" + +" \"attr02-01\":\"value-02-01\",\n" + +" \"attr02-02\":\"value-02-02\"\n" + +" }\n" + +" },\n" + +" {\n" + +" \"attr01\":\"value-01\",\n" + +" \"attr02\": {\n" + +" \"attr02-01\":\"value-02-01\",\n" + +" \"attr02-01\":\"value-02-02\"\n" + +" }\n" + +" }\n" + + "]"; + new JSONArray(str); + fail("Expected an exception"); } catch (JSONException e) { - assertEquals("Expecting an expection message", - "Duplicate key \"attr02-01\" at 269 [character 24 line 13]", - e.getMessage()); + assertEquals("Expecting an expection message", + "Duplicate key \"attr02-01\" at 269 [character 24 line 13]", + e.getMessage()); } } From c365e2a774693a8bdf8b19c6ddcd039678856ed4 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 9 Aug 2017 22:03:09 -0400 Subject: [PATCH 4/6] Remov slf4j reference --- build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle b/build.gradle index 53fbdb3..43656ae 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,6 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.+' testCompile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.1.0' testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5' - testCompile group: 'slf4j.org', name: 'slf4j', version: '1.6.1' // Uncomment if you are testing against a JSON-Java release // testCompile 'org.json:json:20160212' // Uncomment if you have copied a local JSON-Java jar file into this project From 68b262914df7b3a98b2d970edb1adc9b72fed4fb Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 10 Aug 2017 19:06:55 -0400 Subject: [PATCH 5/6] JSONObject(JSONTokener) now points to last character of duplicate key Updating exception message accordingly (position -1) --- src/test/java/org/json/junit/JSONObjectTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 2dcebe4..5d49daa 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -1988,7 +1988,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", + "Duplicate key \"attr03\" at 89 [character 12 line 5]", e.getMessage()); } try { @@ -2007,7 +2007,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", + "Duplicate key \"attr03\" at 89 [character 12 line 5]", e.getMessage()); } try { @@ -2028,7 +2028,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", + "Duplicate key \"attr03\" at 89 [character 12 line 5]", e.getMessage()); } try { @@ -2048,7 +2048,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + "Duplicate key \"attr04-03\" at 214 [character 19 line 9]", e.getMessage()); } try { @@ -2072,7 +2072,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + "Duplicate key \"attr04-03\" at 214 [character 19 line 9]", e.getMessage()); } try { @@ -2098,7 +2098,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + "Duplicate key \"attr04-03\" at 214 [character 19 line 9]", e.getMessage()); } try { @@ -2117,7 +2117,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr01\" at 124 [character 17 line 8]", + "Duplicate key \"attr01\" at 123 [character 16 line 8]", e.getMessage()); } try { @@ -2142,7 +2142,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr02-01\" at 269 [character 24 line 13]", + "Duplicate key \"attr02-01\" at 268 [character 23 line 13]", e.getMessage()); } } From b90bee0f225e2502c8b62d494f571fd27ce5bea4 Mon Sep 17 00:00:00 2001 From: Miguel Date: Mon, 14 Aug 2017 13:05:23 -0400 Subject: [PATCH 6/6] Update error message location (+1) `JSONTokener.back()` call removed from `JSONObject(JSONTokener)` constructor. --- src/test/java/org/json/junit/JSONObjectTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 5d49daa..2dcebe4 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -1988,7 +1988,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 89 [character 12 line 5]", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", e.getMessage()); } try { @@ -2007,7 +2007,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 89 [character 12 line 5]", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", e.getMessage()); } try { @@ -2028,7 +2028,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 89 [character 12 line 5]", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", e.getMessage()); } try { @@ -2048,7 +2048,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 214 [character 19 line 9]", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", e.getMessage()); } try { @@ -2072,7 +2072,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 214 [character 19 line 9]", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", e.getMessage()); } try { @@ -2098,7 +2098,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 214 [character 19 line 9]", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", e.getMessage()); } try { @@ -2117,7 +2117,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr01\" at 123 [character 16 line 8]", + "Duplicate key \"attr01\" at 124 [character 17 line 8]", e.getMessage()); } try { @@ -2142,7 +2142,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr02-01\" at 268 [character 23 line 13]", + "Duplicate key \"attr02-01\" at 269 [character 24 line 13]", e.getMessage()); } }