Java Code Examples for org.json.CDL#toString()
The following examples show how to use
org.json.CDL#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CDLTest.java From JSON-Java-unit-test with Apache License 2.0 | 6 votes |
/** * Given a JSONArray that was not built by CDL, some chars may be * found that would otherwise be filtered out by CDL. */ @Test public void checkSpecialChars() { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); jsonArray.put(jsonObject); // \r will be filtered from name jsonObject.put("Col \r1", "V1"); // \r will be filtered from value jsonObject.put("Col 2", "V2\r"); assertTrue("expected length should be 1",jsonArray.length() == 1); String cdlStr = CDL.toString(jsonArray); jsonObject = jsonArray.getJSONObject(0); assertTrue(cdlStr.contains("\"Col 1\"")); assertTrue(cdlStr.contains("Col 2")); assertTrue(cdlStr.contains("V1")); assertTrue(cdlStr.contains("\"V2\"")); }
Example 2
Source File: CDLTest.java From JSON-Java-unit-test with Apache License 2.0 | 5 votes |
/** * Assert that there is no error for a single escaped quote within a properly embedded quote. */ @Test public void singleEscapedQuote(){ String singleEscape = "Col1, Col2\nVal1, \"\"\"Val2\""; JSONArray jsonArray = CDL.toJSONArray(singleEscape); String cdlStr = CDL.toString(jsonArray); assertTrue(cdlStr.contains("Col1")); assertTrue(cdlStr.contains("Col2")); assertTrue(cdlStr.contains("Val1")); assertTrue(cdlStr.contains("\"Val2")); }
Example 3
Source File: CDLTest.java From JSON-Java-unit-test with Apache License 2.0 | 5 votes |
/** * Assert that there is no error for a single escaped quote within a properly * embedded quote when not the last value. */ @Test public void singleEscapedQuoteMiddleString(){ String singleEscape = "Col1, Col2\nVal1, \"\"\"Val2\"\nVal 3,Val 4"; JSONArray jsonArray = CDL.toJSONArray(singleEscape); String cdlStr = CDL.toString(jsonArray); assertTrue(cdlStr.contains("Col1")); assertTrue(cdlStr.contains("Col2")); assertTrue(cdlStr.contains("Val1")); assertTrue(cdlStr.contains("\"Val2")); }
Example 4
Source File: CDLTest.java From JSON-Java-unit-test with Apache License 2.0 | 5 votes |
/** * call toString with a null array */ @Test public void emptyJSONArrayToString() { JSONArray jsonArray = new JSONArray(); String str = CDL.toString(jsonArray); assertNull("CDL should return null for toString(null)", str); }
Example 5
Source File: CDLTest.java From JSON-Java-unit-test with Apache License 2.0 | 5 votes |
/** * call toString with a null arrays for names and values */ @Test public void nullJSONArraysToString() { String str = CDL.toString(null, null); assertNull("CDL should return null for toString(null)", str); }
Example 6
Source File: CDLTest.java From JSON-Java-unit-test with Apache License 2.0 | 5 votes |
/** * Create a JSONArray from a string of lines, * then convert to string and then back to JSONArray */ @Test public void textToJSONArrayAndBackToString() { JSONArray jsonArray = CDL.toJSONArray(this.lines); String jsonStr = CDL.toString(jsonArray); JSONArray finalJsonArray = CDL.toJSONArray(jsonStr); JSONArray expectedJsonArray = new JSONArray(this.expectedLines); Util.compareActualVsExpectedJsonArrays(finalJsonArray, expectedJsonArray); }
Example 7
Source File: CDLTest.java From JSON-Java-unit-test with Apache License 2.0 | 4 votes |
/** * call toString with a null array */ @Test(expected=NullPointerException.class) public void nullJSONArrayToString() { CDL.toString((JSONArray)null); }