mirror of
https://github.com/stleary/JSON-java.git
synced 2026-01-24 00:03:17 -05:00
fix(#887): regressions, unit tests
- JSONArray now evaluates EOF accordingly for empty Array inputs. - JSONTokener fixed indentation - externalized two JSONMLTest cases
This commit is contained in:
@@ -6,6 +6,11 @@ Public Domain.
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.json.*;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -648,16 +653,10 @@ public class JSONMLTest {
|
||||
// create a JSON array from the original string and make sure it
|
||||
// looks as expected
|
||||
JSONArray jsonArray = JSONML.toJSONArray(xmlStr);
|
||||
// TODO: The next 2 test cases fail due to a strictMode regression. They should be isolated in separate
|
||||
// test cases and fixed.
|
||||
// JSONArray expectedJsonArray = new JSONArray(expectedJSONArrayStr);
|
||||
// Util.compareActualVsExpectedJsonArrays(jsonArray,expectedJsonArray);
|
||||
|
||||
// restore the XML, then make another JSONArray and make sure it
|
||||
// looks as expected
|
||||
String jsonArrayXmlToStr = JSONML.toString(jsonArray);
|
||||
// JSONArray finalJsonArray = JSONML.toJSONArray(jsonArrayXmlToStr);
|
||||
// Util.compareActualVsExpectedJsonArrays(finalJsonArray, expectedJsonArray);
|
||||
|
||||
// lastly, confirm the restored JSONObject XML and JSONArray XML look
|
||||
// reasonably similar
|
||||
@@ -666,6 +665,31 @@ public class JSONMLTest {
|
||||
Util.compareActualVsExpectedJsonObjects(jsonObjectFromObject, jsonObjectFromArray);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenXmlStr_testToJSONArray_shouldEqualExpectedArray() throws IOException {
|
||||
try (Stream<String> jsonLines = Files.lines(
|
||||
Paths.get("src/test/resources/JSONArrayExpectedTestCaseForToJsonArrayTest.json"));
|
||||
Stream<String> xmlLines = Files.lines(Paths.get("src/test/resources/XmlTestCaseTestToJsonArray.xml"))) {
|
||||
|
||||
String xmlStr = xmlLines.collect(Collectors.joining());
|
||||
String expectedJSONArrayStr = jsonLines.collect(Collectors.joining());
|
||||
|
||||
JSONArray jsonArray = JSONML.toJSONArray(xmlStr);
|
||||
JSONArray expectedJsonArray = new JSONArray(expectedJSONArrayStr);
|
||||
|
||||
assertEquals(expectedJsonArray.toString(), jsonArray.toString());
|
||||
//TODO Util.compareActualVsExpectedJsonArrays can be replaced with above assertEquals(expectedJsonArray.toString(), jsonArray.toString())
|
||||
Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray);
|
||||
|
||||
String jsonArrayXmlToStr = JSONML.toString(jsonArray);
|
||||
|
||||
JSONArray finalJsonArray = JSONML.toJSONArray(jsonArrayXmlToStr);
|
||||
|
||||
//TODO Util.compareActualVsExpectedJsonArrays can be replaced with assertEquals(expectedJsonArray.toString(), finalJsonArray.toString())
|
||||
Util.compareActualVsExpectedJsonArrays(finalJsonArray, expectedJsonArray);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an XML document which contains embedded comments into
|
||||
* a JSONArray. Use JSONML.toString() to turn it into a string, then
|
||||
|
||||
Reference in New Issue
Block a user