diff --git a/XMLTest.java b/XMLTest.java index aca2e40..87d956e 100644 --- a/XMLTest.java +++ b/XMLTest.java @@ -10,6 +10,7 @@ import org.junit.Test; /** * Tests for JSON-Java XML.java + * Note: noSpace() will be tested by JSONMLTest */ public class XMLTest { @@ -21,22 +22,25 @@ public class XMLTest { assertTrue("jsonObject should be empty", jsonObject.length() == 0); } - @Test - public void shouldHandleCommentsInXML() { + @Test(expected=NullPointerException.class) + public void shouldHandleNullJSONXML() { + JSONObject jsonObject= null; + String xmlStr = XML.toString(jsonObject); + } + @Test + public void shouldHandleInvalidCDATA() { String xmlStr = - "\n"+ - "\n"+ - "\n"+ - "
\n"+ - " \n"+ - " Joe Tester\n"+ - " \n"+ - " Baker street 5\n"+ - "
\n"+ - "
"; + "\n"+ + "\n"+ + "
\n"+ + " Joe Tester\n"+ + " ![Baker street 5\n"+ + "
\n"+ + "
"; JSONObject jsonObject = XML.toJSONObject(xmlStr); + assertTrue(jsonObject == null); } @Test @@ -47,12 +51,6 @@ public class XMLTest { assertTrue("jsonObject should be empty", jsonObject.length() == 0); } - @Test(expected=NullPointerException.class) - public void shouldHandleNullJSONXML() { - JSONObject jsonObject= null; - String xmlStr = XML.toString(jsonObject); - } - @Test public void shouldHandleEmptyJSONXML() { JSONObject jsonObject= new JSONObject(); @@ -67,15 +65,15 @@ public class XMLTest { " xsi:noNamespaceSchemaLocation='test.xsd'>\n"+ "
\n"+ " Joe Tester\n"+ - " Baker street 5\n"+ + " [CDATA[Baker street 5]\n"+ "
\n"+ ""; String expectedStr = - "{\"addresses\":{\"address\":{\"street\":\"Baker street 5\","+ - "\"name\":\"Joe Tester\"},\"xsi:noNamespaceSchemaLocation\":"+ - "\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+ - "XMLSchema-instance\"}}"; + "{\"addresses\":{\"address\":{\"street\":\"[CDATA[Baker street 5]\","+ + "\"name\":\"Joe Tester\"},\"xsi:noNamespaceSchemaLocation\":"+ + "\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+ + "XMLSchema-instance\"}}"; JSONObject expectedJsonObject = new JSONObject(expectedStr); @@ -83,6 +81,24 @@ public class XMLTest { Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); } + @Test + public void shouldHandleCommentsInXML() { + + String xmlStr = + "\n"+ + "\n"+ + "\n"+ + "
\n"+ + " comment ]]>\n"+ + " Joe Tester\n"+ + " \n"+ + " Baker street 5\n"+ + "
\n"+ + "
"; + JSONObject jsonObject = XML.toJSONObject(xmlStr); + } + @Test public void shouldHandleToString() { String xmlStr =