Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct expected position information in error messages #74

Merged
merged 6 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,26 @@ A unit test has the following stages:
| CDL.java | 98.8% | Reasonable test cases. |
| Cookie.java | 98.9% | Reasonable test cases. |
| CookieList.java |96.5% | Reasonable test cases. |
| EnumTest.java | n/a | Just documenting how enums are handled. |
| HTTP.java | 98.7%| Coverage > 90% |
| HTTP.java | 98.8%| Coverage > 90% |
| HTTPTokener.java |93.2% | No test |
| JSONArray.java |95.9% | Reasonable test cases |
| JSONException.java | 26.7% | No test |
| JSONML.java | 86.8%| In progress |
| JSONObject | 94.0% | Reasonable test cases |
| JSONObject.Null | 87.5% | No test |
| JSONArray.java |88.3% | Reasonable test cases. Need new tests for newer API functions |
| JSONException.java | 100% | No test |
| JSONML.java | 84.4%| In progress |
| JSONObject | 96.7% | Reasonable test cases |
| JSONObject.Null | 77.8% | No test |
| JSONPointer | 96.3% | Reasonable test cases |
| JSONPointerException | 100% | No test |
| JSONString.java | | No test |
| JSONStringer.java | 93.8%| Coverage > 90% |
| JSONTokener.java | 72.1% | In progress |
| JSONWriter.java | 87.5% | No test |
| Property.java | 94.8% | Coverage > 90% |
| XML.java | 87.4% | In progress |
| XMLTokener.java| 82.7%| No test |
| JSONTokener.java | 87.5% | In progress |
| JSONWriter.java | 89.15% | No test |
| Property.java | 95.8% | Coverage > 90% |
| XML.java | 77.3% | In progress |
| XMLTokener.java| 82.4%| No test |

| Files used in test |
| ------------- |
| EnumTest.java |
| MyBean.java |
| MyBigNumberBean.java |
| MyEnum.java |
Expand Down
73 changes: 44 additions & 29 deletions src/test/java/org/json/junit/CDLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public void unbalancedQuoteInName() {
String badLine = "Col1, \"Col2\nVal1, Val2";
try {
CDL.toJSONArray(badLine);
assertTrue("Expecting an exception", false);
fail("Expecting an exception");
} catch (JSONException e) {
assertTrue("Expecting an exception message",
"Missing close quote '\"'. at 12 [character 0 line 2]".
equals(e.getMessage()));
assertEquals("Expecting an exception message",
"Missing close quote '\"'. at 12 [character 0 line 2]",
e.getMessage());
}
}

Expand All @@ -78,11 +78,11 @@ public void unbalancedQuoteInValue() {
String badLine = "Col1, Col2\n\"Val1, Val2";
try {
CDL.toJSONArray(badLine);
assertTrue("Expecting an exception", false);
fail("Expecting an exception");
} catch (JSONException e) {
assertTrue("Expecting an exception message",
"Missing close quote '\"'. at 23 [character 12 line 3]".
equals(e.getMessage()));
assertEquals("Expecting an exception message",
"Missing close quote '\"'. at 22 [character 11 line 2]",
e.getMessage());

}
}
Expand All @@ -96,11 +96,11 @@ public void nullInName() {
String badLine = "C\0ol1, Col2\nVal1, Val2";
try {
CDL.toJSONArray(badLine);
assertTrue("Expecting an exception", false);
fail("Expecting an exception");
} catch (JSONException e) {
assertTrue("Expecting an exception message",
"Bad character 'o' (111). at 3 [character 4 line 1]".
equals(e.getMessage()));
assertEquals("Expecting an exception message",
"Bad character 'o' (111). at 2 [character 3 line 1]",
e.getMessage());

}
}
Expand All @@ -114,11 +114,11 @@ public void unbalancedEscapedQuote(){
String badLine = "Col1, Col2\n\"Val1, \"\"Val2\"\"";
try {
CDL.toJSONArray(badLine);
assertTrue("Expecting an exception", false);
fail("Expecting an exception");
} catch (JSONException e) {
assertTrue("Expecting an exception message",
"Missing close quote '\"'. at 27 [character 16 line 3]".
equals(e.getMessage()));
assertEquals("Expecting an exception message",
"Missing close quote '\"'. at 26 [character 15 line 2]",
e.getMessage());

}
}
Expand All @@ -128,15 +128,30 @@ public void unbalancedEscapedQuote(){
*/
@Test
public void singleEscapedQuote(){
String singleEscape = "Col1, Col2\nVal1, \"\"\"Val2\"";
String singleEscape = "Col1, Col2\nVal1, \"\"\"Val2\"";
JSONArray jsonArray = CDL.toJSONArray(singleEscape);

String cdlStr = CDL.toString(jsonArray);
assertTrue(cdlStr.contains("Col1"));
assertTrue(cdlStr.contains("Col2"));
assertTrue(cdlStr.contains("Val1"));
assertTrue(cdlStr.contains("\"Val2"));
}

/**
* Assert that there is no error for a single escaped quote within a properly
* embedded quote when not the last value.
*/
@Test
public void singleEscapedQuoteMiddleString(){
String singleEscape = "Col1, Col2\nVal1, \"\"\"Val2\"\nVal 3,Val 4";
JSONArray jsonArray = CDL.toJSONArray(singleEscape);

String cdlStr = CDL.toString(jsonArray);
assertTrue(cdlStr.contains("Col1"));
assertTrue(cdlStr.contains("Col2"));
assertTrue(cdlStr.contains("Val1"));
assertTrue(cdlStr.contains("\"Val2"));
}

/**
Expand All @@ -149,12 +164,12 @@ public void badEscapedQuote(){

try {
CDL.toJSONArray(badLine);
assertTrue("Expecting an exception", false);
fail("Expecting an exception");
} catch (JSONException e) {
System.out.println("Message" + e.getMessage());
assertTrue("Expecting an exception message",
"Bad character 'V' (86). at 20 [character 9 line 3]".
equals(e.getMessage()));
assertEquals("Expecting an exception message",
"Bad character 'V' (86). at 20 [character 9 line 2]",
e.getMessage());

}

Expand Down Expand Up @@ -186,8 +201,8 @@ public void emptyString() {
public void onlyColumnNames() {
String columnNameStr = "col1, col2, col3";
JSONArray jsonArray = CDL.toJSONArray(columnNameStr);
assertTrue("CDL should return null when only 1 row is given",
jsonArray == null);
assertNull("CDL should return null when only 1 row is given",
jsonArray);
}

/**
Expand All @@ -197,8 +212,8 @@ public void onlyColumnNames() {
public void emptyLinesToJSONArray() {
String str = " , , , \n , , , ";
JSONArray jsonArray = CDL.toJSONArray(str);
assertTrue("JSONArray should be null for no content",
jsonArray == null);
assertNull("JSONArray should be null for no content",
jsonArray);
}

/**
Expand All @@ -208,8 +223,8 @@ public void emptyLinesToJSONArray() {
public void emptyJSONArrayToString() {
JSONArray jsonArray = new JSONArray();
String str = CDL.toString(jsonArray);
assertTrue("CDL should return null for toString(null)",
str == null);
assertNull("CDL should return null for toString(null)",
str);
}

/**
Expand All @@ -218,8 +233,8 @@ public void emptyJSONArrayToString() {
@Test
public void nullJSONArraysToString() {
String str = CDL.toString(null, null);
assertTrue("CDL should return null for toString(null)",
str == null);
assertNull("CDL should return null for toString(null)",
str);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/json/junit/CookieListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public void malFormedCookieListException() {
String cookieStr = "thisCookieHasNoEqualsChar";
try {
CookieList.toJSONObject(cookieStr);
assertTrue("should throw an exception", false);
fail("should throw an exception");
} catch (JSONException e) {
/**
* Not sure of the missing char, but full string compare fails
*/
assertTrue("Expecting an exception message",
e.getMessage().startsWith("Expected '=' and instead saw '") &&
e.getMessage().endsWith("' at 27 [character 28 line 1]"));
assertEquals("Expecting an exception message",
"Expected '=' and instead saw '' at 25 [character 26 line 1]",
e.getMessage());
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/test/java/org/json/junit/CookieTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public void malFormedNameValueException() {
String cookieStr = "thisCookieHasNoEqualsChar";
try {
Cookie.toJSONObject(cookieStr);
assertTrue("Expecting an exception", false);
fail("Expecting an exception");
} catch (JSONException e) {
assertTrue("Expecting an exception message",
e.getMessage().startsWith("Expected '=' and instead saw '")
&& e.getMessage().endsWith("' at 27 [character 28 line 1]"));
assertEquals("Expecting an exception message",
"Expected '=' and instead saw '' at 25 [character 26 line 1]",
e.getMessage());
}
}

Expand All @@ -61,11 +61,11 @@ public void malFormedAttributeException() {
String cookieStr = "this=Cookie;myAttribute";
try {
Cookie.toJSONObject(cookieStr);
assertTrue("Expecting an exception", false);
fail("Expecting an exception");
} catch (JSONException e) {
assertTrue("Expecting an exception message",
"Missing '=' in cookie parameter. at 25 [character 26 line 1]".
equals(e.getMessage()));
assertEquals("Expecting an exception message",
"Missing '=' in cookie parameter. at 23 [character 24 line 1]",
e.getMessage());
}
}

Expand All @@ -79,11 +79,11 @@ public void emptyStringCookieException() {
String cookieStr = "";
try {
Cookie.toJSONObject(cookieStr);
assertTrue("Expecting an exception", false);
fail("Expecting an exception");
} catch (JSONException e) {
assertTrue("Expecting an exception message",
e.getMessage().startsWith("Expected '=' and instead saw '") &&
e.getMessage().endsWith("' at 2 [character 3 line 1]"));
assertEquals("Expecting an exception message",
"Expected '=' and instead saw '' at 0 [character 1 line 1]",
e.getMessage());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/json/junit/JSONArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public void emptStr() {
try {
assertNull("Should throw an exception", new JSONArray(str));
} catch (JSONException e) {
assertTrue("Expected an exception message",
"A JSONArray text must start with '[' at 1 [character 2 line 1]".
equals(e.getMessage()));
assertEquals("Expected an exception message",
"A JSONArray text must start with '[' at 0 [character 1 line 1]",
e.getMessage());
}
}

Expand Down
Loading