47 Commits

Author SHA1 Message Date
Allon Mureinik
4c8cac22a8 Use System.lineSeparator()
Use the built-in System.lineSeparator() instead of implementing it
ourselves with System.getProperty("line.separator") in order to clean
up the code and make it easier to maintain.
2023-10-05 19:47:33 +03:00
Allon Mureinik
fe45fa9cfb Fix XMLTest on Windows
XMLTest.testIndentComplicatedJsonObjectWithArrayAndWithConfig fails
when run on Windows due to mismatching linebreaks (that aren't
important for the test's functionality) between the actual and
expected strings.

For the actual strings, linebreaks are canonized to the platform's
native linebreak using `replaceAll("\\n|\\r\\n",
System.getProperty("line.separator")`. However, the expected result is
read from a file, and is left with the linebreaks that were originally
used to create it.

The solution is to perform the same canonization on both strings.

Closes #781
2023-10-05 15:36:07 +03:00
dburbrid
3d524349a1 Correction of bug when compiling/testing on Windows: Issue537 file must be read as UTF-8 (Issue 745) 2023-06-26 09:33:03 +01:00
superMaaax
48fb5261fe Fixed Flaky Tests Caused by JSON permutations
###Description
Flaky Tests found using NonDex by running the commands -
mvn -pl . edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.json.junit.XMLTest#testIndentComplicatedJsonObject

mvn -pl . edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.json.junit.XMLTest#testIndentSimpleJsonArray

mvn -pl . edu.illinois:nondex-maven-plugin:2.1.1:nondex -Dtest=org.json.junit.XMLTest#testIndentSimpleJsonObject

The logged failure was-

[ERROR] Failures:
[ERROR] XMLTest.testIndentSimpleJsonObject:1193 expected:<...>
<employee>
<[married>true</married>
<name>sonoo</name>
<salary>56000</salary]>
</employee>
</Te...> but was:<...>
<employee>
<[name>sonoo</name>
<salary>56000</salary>
<married>true</married]>
</employee>
</Te...>

The issue is the same for all three tests, so here I only show the failure message for the third test (to reduce the length of the error message).

### Investigation

The tests fail with a comparison error while comparing an expected JSON String and the result from the value returned from XML.toString(). The toString function of XML makes no guarantees as to the iteration order of the attributes in the object. This makes the test outcome non-deterministic, and the test fails whenever the function returns a mismatch in order of the elements in the JSON String. To fix this, the expected and actual keys should be checked in a more deterministic way so that the assertions do not fail.

### Fix

Expected and Actual values can be converted into JSONObject and the similar function can be used to compare these objects. As this function compares the values inside the JSONObjects without needing order, the test becomes deterministic and ensures that the flakiness from the test is removed.

The PR does not introduce a breaking change.
2023-03-21 20:58:32 -05:00
Cleydyr de Albuquerque
651511f500 tests: add new test to verify that an XML having the permitted nesting depth can be converted 2023-02-01 20:22:47 +01:00
Cleydyr de Albuquerque
a14cb12c85 refactor: keep consistence with other tests and tidy up constant 2023-02-01 20:22:32 +01:00
Cleydyr de Albuquerque
f566a1d9ee fix: limit the nesting depth 2023-02-01 16:26:58 +01:00
Dean
85495facbd
Corrected test 2022-10-10 11:12:35 +01:00
Dean
7aba3ac941
System line seperator now being used in JUnit test 2022-10-10 11:09:42 +01:00
Dean
a2c0562e04
Removed unused import 2022-10-07 15:04:09 +01:00
Dean
4a8ff28fd8
Reduced Test code length by using resources 2022-10-07 10:35:06 +01:00
Dean
fa457a4113
Test cases for XML toString indentation 2022-10-06 12:01:26 +01:00
Dean
b7f708b222
Altered XML toString to allow indentation param 2022-10-06 12:01:13 +01:00
stleary
6daabb43ab update-copyright - Replace copyright and license restrictions with Public Domain 2022-08-23 20:00:25 -05:00
stleary
76ec2fe5a2 Revert accidentally changed file 2021-06-22 19:46:33 -05:00
stleary
8f3e5ade18 Add logo image 2021-06-22 19:34:22 -05:00
Rahul Kumar
56d4130a86 Added shallow copy for config map 2020-09-06 11:17:10 +05:30
Rahul Kumar
310f18fcdc Addressed comment 2020-09-03 11:17:10 +05:30
Rahul Kumar
0a8091c954 Added documentation 2020-08-05 22:25:45 +05:30
Rahul Kumar
61c1a882d6 Added configuration support for type conversion using Map 2020-08-03 08:54:59 +05:30
Rahul Kumar
250f74ef4d Added type conversion support 2020-08-03 08:18:20 +05:30
stleary
98cd8ef8b2 fix CI build error 2020-07-24 03:24:41 -05:00
Sean Leary
78528102d0
Merge pull request #543 from johnjaylward/RefactorXmlConfiguration
Refactor XMLConfiguration to use Builder Pattern
2020-07-24 02:49:28 -05:00
Sean Leary
0e34d8d383
Merge pull request #539 from stleary/unit-tests-1.6
Bring Junit tests to Java 1.6 compatibility
2020-07-24 02:48:38 -05:00
John J. Aylward
4f1c8b2d6f formatting 2020-07-21 11:30:35 -04:00
John J. Aylward
5a31f9ef5f Refs #541
Updates XML configuration to use a builder pattern instead of
constructors with many parameters
2020-07-21 11:08:40 -04:00
John J. Aylward
e0a6c2ef34 refs #537 Show error when unescaping all-caps entity directly 2020-07-20 18:36:52 -04:00
John J. Aylward
c98da43184 Refs #537 Add test cases to verify no issue 2020-07-20 18:25:51 -04:00
stleary
c63e78bbc7 initial commit 2020-07-18 17:14:39 -05:00
John J. Aylward
c11c006e88 fix tests to not depend on HashSet key order 2020-06-05 19:09:10 -04:00
stleary
2b0a8838ef gradle support 2020-05-22 11:17:44 -05:00
meiskalt7
fa173fa51a add test for xsi:nil to null conversion disabled 2019-04-21 00:53:39 +07:00
meiskalt7
614e8359b9 add test for xsi:nil to null conversion 2019-04-18 21:42:57 +07:00
John J. Aylward
e7f7d348cd * updates tests to cover more cases of tokenizing
* uncomments tests that should now work
2018-12-10 11:45:10 -05:00
Sean Leary
e699abb1c6
Merge pull request #61 from johnjaylward/XmlEscape
Test cases Xml escapes
2018-12-08 20:09:03 -06:00
Andrei Paikin
d00501eabd add usage of isEmpty method 2018-05-25 22:47:05 +03:00
John J. Aylward
2713f2e2a4 Adds testing for unicode entities 2017-08-19 18:45:53 -04:00
John J. Aylward
cb61bbf720 New tests for XML unescaping 2017-08-19 18:19:22 -04:00
John J. Aylward
0e612ba8a4 More test corrections for correct position reports in error messages 2017-06-21 19:56:00 -04:00
John J. Aylward
3081b4bd96 Fixes for failing tests due to android integration 2017-06-21 14:59:42 -04:00
John J. Aylward
9df5d34bbe * Update link in the README to the main JSON-Java repo
* Cleans up some warnings
* Adds new test for bug https://github.com/stleary/JSON-java/issues/332
* Adds some resource handling for string writers using pre-java1.7
support. I know StringWriters don't need a close method called, but the
tests should still handle their resources properly.
2017-04-27 12:39:42 -04:00
John J. Aylward
f6a00e94c7 adds test for unicode that has surrogate pairs 2016-09-22 16:12:00 -04:00
John J. Aylward
2b87f334d0 Update test cases to support ISO Control encoding changes. 2016-09-22 14:13:48 -04:00
John J. Aylward
5027a283c1 Adds test for escaping from a JSONObject to XML 2016-09-22 13:09:32 -04:00
John J. Aylward
c8563ff93d new test case for XML changes 2016-09-22 12:38:30 -04:00
John J. Aylward
215321cd28 updates Test cases to support new JSONML and XML conversion options 2016-07-18 15:04:03 -04:00
John J. Aylward
80f9e48e64 Moves src folder to simplify build.gradle configuration. If JSON-Java source is merged, it's src fold would now be src/main/java/org.json/ instead of src/main/org.json as well. 2016-06-16 12:20:54 -04:00