From 4b0db65877c18132d6b45b0a147ac5ba0c912fd4 Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Mon, 12 Oct 2015 13:48:05 -0400 Subject: [PATCH 1/2] Fixes NPE in XML --- XMLTest.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/XMLTest.java b/XMLTest.java index 2f770ef..f680e18 100644 --- a/XMLTest.java +++ b/XMLTest.java @@ -1,12 +1,17 @@ package org.json.junit; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import java.io.*; +import java.io.IOException; -import org.json.*; -import org.junit.*; -import org.junit.rules.*; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.XML; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; /** @@ -180,9 +185,8 @@ public class XMLTest { /** * Null JSONObject in XML.toString() - * Expects NullPointerException */ - @Test(expected=NullPointerException.class) + @Test public void shouldHandleNullJSONXML() { JSONObject jsonObject= null; XML.toString(jsonObject); From cb63a968fa68ac39f94dfffb0962d91ed1d28862 Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Mon, 12 Oct 2015 14:49:18 -0400 Subject: [PATCH 2/2] fixes test case to validate the input/output of the function being tested --- XMLTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/XMLTest.java b/XMLTest.java index f680e18..fb3b42c 100644 --- a/XMLTest.java +++ b/XMLTest.java @@ -189,7 +189,8 @@ public class XMLTest { @Test public void shouldHandleNullJSONXML() { JSONObject jsonObject= null; - XML.toString(jsonObject); + String actualXml=XML.toString(jsonObject); + assertEquals("generated XML does not equal expected XML","\"null\"",actualXml); } /**