Skip to content
Merged
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
72 changes: 64 additions & 8 deletions src/test/java/org/json/junit/JSONObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1973,13 +1973,7 @@ public void jsonObjectParsingErrors() {
"Null pointer",
e.getMessage());
}
try {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, 0);
fail("Expected an exception");
} catch (NullPointerException ignored) {
}

try {
// multiple putOnce key
JSONObject jsonObject = new JSONObject("{}");
Expand Down Expand Up @@ -2182,6 +2176,10 @@ public void jsonObjectPutOnceNull() {
JSONObject jsonObject = new JSONObject();
jsonObject.putOnce(null, null);
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
jsonObject.putOnce("", null);
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
jsonObject.putOnce(null, "");
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
}

/**
Expand Down Expand Up @@ -2453,7 +2451,7 @@ public void write() throws IOException {
* Confirms that exceptions thrown when writing values are wrapped properly.
*/
@Test
public void testJSONWriterException() throws IOException {
public void testJSONWriterException() {
final JSONObject jsonObject = new JSONObject();

jsonObject.put("someKey",new BrokenToString());
Expand Down Expand Up @@ -2893,4 +2891,62 @@ public void testExceptionalBean() {
assertTrue(jo.get("closeable") instanceof JSONObject);
assertTrue(jo.getJSONObject("closeable").has("string"));
}

@Test(expected=NullPointerException.class)
public void testPutNullBoolean() {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, false);
fail("Expected an exception");
}
@Test(expected=NullPointerException.class)
public void testPutNullCollection() {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, Collections.emptySet());
fail("Expected an exception");
}
@Test(expected=NullPointerException.class)
public void testPutNullDouble() {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, 0.0d);
fail("Expected an exception");
}
@Test(expected=NullPointerException.class)
public void testPutNullFloat() {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, 0.0f);
fail("Expected an exception");
}
@Test(expected=NullPointerException.class)
public void testPutNullInt() {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, 0);
fail("Expected an exception");
}
@Test(expected=NullPointerException.class)
public void testPutNullLong() {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, 0L);
fail("Expected an exception");
}
@Test(expected=NullPointerException.class)
public void testPutNullMap() {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, Collections.emptyMap());
fail("Expected an exception");
}
@Test(expected=NullPointerException.class)
public void testPutNullObject() {
// null put key
JSONObject jsonObject = new JSONObject("{}");
jsonObject.put(null, new Object());
fail("Expected an exception");
}

}