mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
in progress
This commit is contained in:
parent
4c6da0e6f9
commit
2df27fc6e7
1 changed files with 40 additions and 24 deletions
64
XMLTest.java
64
XMLTest.java
|
@ -10,6 +10,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for JSON-Java XML.java
|
* Tests for JSON-Java XML.java
|
||||||
|
* Note: noSpace() will be tested by JSONMLTest
|
||||||
*/
|
*/
|
||||||
public class XMLTest {
|
public class XMLTest {
|
||||||
|
|
||||||
|
@ -21,22 +22,25 @@ public class XMLTest {
|
||||||
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
|
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected=NullPointerException.class)
|
||||||
public void shouldHandleCommentsInXML() {
|
public void shouldHandleNullJSONXML() {
|
||||||
|
JSONObject jsonObject= null;
|
||||||
|
String xmlStr = XML.toString(jsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHandleInvalidCDATA() {
|
||||||
String xmlStr =
|
String xmlStr =
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
"<!-- this is a comment -->\n"+
|
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
||||||
"<addresses>\n"+
|
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
||||||
" <address>\n"+
|
" <address>\n"+
|
||||||
" <!-- this is another comment -->\n"+
|
" <name>Joe Tester</name>\n"+
|
||||||
" <name>Joe Tester</name>\n"+
|
" <street>![Baker street 5</street>\n"+
|
||||||
" <!-- this is a multi line \n"+
|
" </address>\n"+
|
||||||
" comment -->\n"+
|
"</addresses>";
|
||||||
" <street>Baker street 5</street>\n"+
|
|
||||||
" </address>\n"+
|
|
||||||
"</addresses>";
|
|
||||||
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
||||||
|
assertTrue(jsonObject == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -47,12 +51,6 @@ public class XMLTest {
|
||||||
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
|
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
|
||||||
public void shouldHandleNullJSONXML() {
|
|
||||||
JSONObject jsonObject= null;
|
|
||||||
String xmlStr = XML.toString(jsonObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHandleEmptyJSONXML() {
|
public void shouldHandleEmptyJSONXML() {
|
||||||
JSONObject jsonObject= new JSONObject();
|
JSONObject jsonObject= new JSONObject();
|
||||||
|
@ -67,15 +65,15 @@ public class XMLTest {
|
||||||
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
||||||
" <address>\n"+
|
" <address>\n"+
|
||||||
" <name>Joe Tester</name>\n"+
|
" <name>Joe Tester</name>\n"+
|
||||||
" <street>Baker street 5</street>\n"+
|
" <street>[CDATA[Baker street 5]</street>\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
|
|
||||||
String expectedStr =
|
String expectedStr =
|
||||||
"{\"addresses\":{\"address\":{\"street\":\"Baker street 5\","+
|
"{\"addresses\":{\"address\":{\"street\":\"[CDATA[Baker street 5]\","+
|
||||||
"\"name\":\"Joe Tester\"},\"xsi:noNamespaceSchemaLocation\":"+
|
"\"name\":\"Joe Tester\"},\"xsi:noNamespaceSchemaLocation\":"+
|
||||||
"\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+
|
"\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+
|
||||||
"XMLSchema-instance\"}}";
|
"XMLSchema-instance\"}}";
|
||||||
|
|
||||||
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
||||||
|
|
||||||
|
@ -83,6 +81,24 @@ public class XMLTest {
|
||||||
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHandleCommentsInXML() {
|
||||||
|
|
||||||
|
String xmlStr =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
|
"<!-- this is a comment -->\n"+
|
||||||
|
"<addresses>\n"+
|
||||||
|
" <address>\n"+
|
||||||
|
" <![CDATA[ this is -- <another> comment ]]>\n"+
|
||||||
|
" <name>Joe Tester</name>\n"+
|
||||||
|
" <!-- this is a - multi line \n"+
|
||||||
|
" comment -->\n"+
|
||||||
|
" <street>Baker street 5</street>\n"+
|
||||||
|
" </address>\n"+
|
||||||
|
"</addresses>";
|
||||||
|
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHandleToString() {
|
public void shouldHandleToString() {
|
||||||
String xmlStr =
|
String xmlStr =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue