Skip to content

Commit fafaeb7

Browse files
author
Zach
committed
Added simple test case
1 parent e356739 commit fafaeb7

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/test/java/org/json/junit/XMLConfigurationTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ of this software and associated documentation files (the "Software"), to deal
3535
import java.io.IOException;
3636
import java.io.Reader;
3737
import java.io.StringReader;
38+
import java.util.HashSet;
39+
import java.util.Set;
3840

3941
import org.json.JSONArray;
4042
import org.json.JSONException;
@@ -903,6 +905,34 @@ public void testConfig() {
903905
Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray);
904906

905907
}
908+
909+
/**
910+
* Confirm XMLParserConfiguration functionality
911+
*/
912+
@Test
913+
public void testSimpleForceList() {
914+
915+
String xmlStr =
916+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
917+
"<addresses>\n"+
918+
" <address>\n"+
919+
" <name>Sherlock Holmes</name>\n"+
920+
" </address>\n"+
921+
"</addresses>";
922+
923+
String expectedStr = "{\"addresses\":[{\"address\":{\"name\":\"Sherlock Holmes\"}}]}";
924+
925+
Set<String> forceList = new HashSet<String>();
926+
forceList.add("addresses");
927+
928+
XMLParserConfiguration config =
929+
new XMLParserConfiguration()
930+
.withForceList(forceList);
931+
JSONObject jsonObject = XML.toJSONObject(xmlStr, config);
932+
JSONObject expetedJsonObject = new JSONObject(expectedStr);
933+
934+
Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject);
935+
}
906936

907937

908938
/**

0 commit comments

Comments
 (0)