1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Merge pull request #50 from johnjaylward/issue240

Tests for Issue #240 in JSON-Java
This commit is contained in:
Sean Leary 2016-06-17 09:36:42 -05:00 committed by GitHub
commit 01af31718e
26 changed files with 38 additions and 18 deletions

6
.gitignore vendored
View file

@ -3,3 +3,9 @@ build
.classpath .classpath
.project .project
.settings/ .settings/
/.gradle/
/gradle/
/gradlew
/gradlew.bat
.gitmodules
src/main/

View file

@ -29,15 +29,22 @@ git clone https://github.com/stleary/JSON-Java-unit-test.git .
\# Create a directory structure for the JSON-Java code \# Create a directory structure for the JSON-Java code
```` ````
# Windows version # Windows version
md /s src\org\json md /s src\main\java\org\json
# *nix version
mkdir -p src/main/java/org/json
```` ````
\# clone JSON-Java \# clone JSON-Java
```` ````
git clone https://github.com/stleary/JSON-Java.git src\org\json #Windows version
git clone https://github.com/stleary/JSON-Java.git src\main\java\org\json
#*Nix version
git clone https://github.com/stleary/JSON-Java.git src/main/java/org/json
```` ````
\# Build, then execute the unit tests and code coverage \# Build, then execute the unit tests and code coverage
```` ````
gradle clean build test jacocoTestReport gradle clean build test jacocoTestReport
```` ````
Unit test results will be in build\reports\tests\index.html<br> Unit test results will be in build\reports\tests\index.html<br>
Code coverage will be in build\reports\jacoco\html\index.html Code coverage will be in build\reports\jacoco\html\index.html
@ -55,7 +62,7 @@ When adding a new unit test, don't forget to update <b>JunitTestSuite.java</b>.
<b>The fundamental issues with JSON-Java testing are:</b><br> <b>The fundamental issues with JSON-Java testing are:</b><br>
* <b>JSONObjects</b> are unordered, making simple string comparison ineffective. * <b>JSONObjects</b> are unordered, making simple string comparison ineffective.
* Comparisons via **equals()** is not currently supported. Neither <b>JSONArray</b> nor <b>JSONObject</b> overrride <b>hashCode()</b> or <b>equals()</b>, so comparison defaults to the <b>Object</b> equals(), which is not useful. * Comparisons via **equals()** is not currently supported. Neither <b>JSONArray</b> nor <b>JSONObject</b> override <b>hashCode()</b> or <b>equals()</b>, so comparison defaults to the <b>Object</b> equals(), which is not useful.
* Access to the <b>JSONArray</b> and <b>JSONObject</b> internal containers for comparison is not currently available. * Access to the <b>JSONArray</b> and <b>JSONObject</b> internal containers for comparison is not currently available.
<b>General issues with unit testing are:</b><br> <b>General issues with unit testing are:</b><br>

View file

@ -4,21 +4,8 @@ apply plugin: 'jacoco'
sourceSets { sourceSets {
// Uncomment main if you have merged JSON-Java and JSON-Java-unit-test code // Uncomment main if you have merged JSON-Java and JSON-Java-unit-test code
main { main
java { test
srcDir 'src'
exclude 'test/'
}
}
test {
java {
srcDir 'src/test'
exclude 'resources/'
}
resources {
srcDir 'resources'
}
}
} }
repositories { repositories {

View file

@ -1564,6 +1564,26 @@ public class JSONObjectTest {
assertTrue("expected val3", "val3".equals(mapJsonObject.query("/key3"))); assertTrue("expected val3", "val3".equals(mapJsonObject.query("/key3")));
} }
/**
* RFC 7159 defines control characters to be U+0000 through U+001F. This test verifies that the parser is checking for these in expected ways.
*/
@Test
public void jsonObjectParseControlCharacters(){
for(int i = 0;i<=0x001f;i++){
final String charString = String.valueOf((char)i);
final String source = "{\"key\":\""+charString+"\"}";
try {
JSONObject jo = new JSONObject(source);
assertTrue("Expected "+charString+"("+i+") in the JSON Object but did not find it.",charString.equals(jo.getString("key")));
} catch (JSONException ex) {
assertTrue("Only \\0 (U+0000), \\n (U+000A), and \\r (U+000D) should cause an error. Instead "+charString+"("+i+") caused an error",
i=='\0' || i=='\n' || i=='\r'
);
}
}
}
/** /**
* Explore how JSONObject handles parsing errors. * Explore how JSONObject handles parsing errors.
*/ */