Added simple test case

This commit is contained in:
Zach 2021-11-19 20:32:36 -06:00
parent e356739a2f
commit fafaeb7aa6

View File

@ -35,6 +35,8 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -904,6 +906,34 @@ public class XMLConfigurationTest {
} }
/**
* Confirm XMLParserConfiguration functionality
*/
@Test
public void testSimpleForceList() {
String xmlStr =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
"<addresses>\n"+
" <address>\n"+
" <name>Sherlock Holmes</name>\n"+
" </address>\n"+
"</addresses>";
String expectedStr = "{\"addresses\":[{\"address\":{\"name\":\"Sherlock Holmes\"}}]}";
Set<String> forceList = new HashSet<String>();
forceList.add("addresses");
XMLParserConfiguration config =
new XMLParserConfiguration()
.withForceList(forceList);
JSONObject jsonObject = XML.toJSONObject(xmlStr, config);
JSONObject expetedJsonObject = new JSONObject(expectedStr);
Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject);
}
/** /**
* Convenience method, given an input string and expected result, * Convenience method, given an input string and expected result,