Skip to content

Commit 7fa08cc

Browse files
author
Carter Page
committed
Fixed javadocs to be JDK 8 compatible.
1 parent 8bf08ec commit 7fa08cc

File tree

12 files changed

+173
-123
lines changed

12 files changed

+173
-123
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ Version 1.4.0 - 10/30/2016
1414

1515
Version 1.3.0 - 12/16/2015
1616
--------------------------
17-
- Fix & improve ArrayValueMatcher JavaDoc (dmackinder)
17+
- Fix & improve ArrayValueMatcher JavaDoc (thanks dmackinder!)
1818
Fix final JavaDoc example and add new example showing how to verify
1919
every array element using a custom comparator
2020
- Fix URL in pom.xml (aukevanleeuwen)
21-
- Update JSONCompareResult.java adding 2 new lists for missing and unexpected fileds (riccorazza)
22-
- Includes missing imports in test class (javierseixas)
21+
- Update JSONCompareResult.java adding 2 new lists for missing and unexpected fileds (thanks riccorazza!)
22+
- Includes missing imports in test class (thanks javierseixas!)
2323

2424
Version 1.2.3 - 2/5/2014
2525
------------------------
26-
- This edition brought to you by dmackinder (thanks!)
26+
- This edition brought to you by dmackinder (thanks dmackinder!)
2727
- Added array size comparator enhancements.
2828
- Added ArrayValueMatcher to simplify verification of range of array elements.
2929
- Improve diagnostics from RegularExpressionValueMatcher.

src/main/java/org/json/JSONString.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public interface JSONString {
1414
/**
1515
* The toJSONString method allows a class to produce its own JSON
1616
* serialization.
17+
*
18+
* @return String representation of JSON object
1719
* */
1820
String toJSONString();
1921

src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,62 +22,73 @@
2222
*
2323
* <p>Assuming JSON to be verified is held in String variable ARRAY_OF_JSONOBJECTS and contains:</p>
2424
*
25-
* <code>{a:[{background:white,id:1,type:row}, {background:grey,id:2,type:row}, {background:white,id:3,type:row}, {background:grey,id:4,type:row}]}</code>
25+
* <pre>{@code
26+
* {a:[{background:white, id:1, type:row},
27+
* {background:grey, id:2, type:row},
28+
* {background:white, id:3, type:row},
29+
* {background:grey, id:4, type:row}]}
30+
* }</pre>
2631
*
2732
* <p>then:</p>
2833
*
2934
* <p>To verify that the 'id' attribute of first element of array 'a' is '1':</p>
3035
*
31-
* <code>
32-
* JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);<br/>
33-
* Customization customization = new Customization("a", new ArrayValueMatcher&lt;Object&gt;(comparator, 0));<br/>
34-
* JSONAssert.assertEquals("{a:[{id:1}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization));
35-
* </code>
36+
* <pre>{@code
37+
* JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
38+
* Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 0));
39+
* JSONAssert.assertEquals("{a:[{id:1}]}", ARRAY_OF_JSONOBJECTS,
40+
* new CustomComparator(JSONCompareMode.LENIENT, customization));
41+
* }</pre>
3642
*
3743
* <p>To simplify complexity of expected JSON string, the value <code>"a:[{id:1}]}"</code> may be replaced by <code>"a:{id:1}}"</code></p>
3844
*
3945
* <p>To verify that the 'type' attribute of second and third elements of array 'a' is 'row':</p>
4046
*
41-
* <code>
42-
* JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);<br/>
43-
* Customization customization = new Customization("a", new ArrayValueMatcher&lt;Object&gt;(comparator, 1, 2));<br/>
44-
* JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization));
45-
* </code>
47+
* <pre>{@code
48+
* JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
49+
* Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 1, 2));
50+
* JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS,
51+
* new CustomComparator(JSONCompareMode.LENIENT, customization));
52+
* }</pre>
4653
*
4754
* <p>To verify that the 'type' attribute of every element of array 'a' is 'row':</p>
4855
*
49-
* <code>
50-
* JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);<br/>
51-
* Customization customization = new Customization("a", new ArrayValueMatcher&lt;Object&gt;(comparator));<br/>
52-
* JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization));
53-
* </code>
56+
* <pre>{@code
57+
* JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
58+
* Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator));
59+
* JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS,
60+
* new CustomComparator(JSONCompareMode.LENIENT, customization));
61+
* }</pre>
5462
*
5563
* <p>To verify that the 'id' attribute of every element of array 'a' matches regular expression '\d+'. This requires a custom comparator to specify regular expression to be used to validate each array element, hence the array of Customization instances:</p>
5664
*
57-
* <code>
58-
* // get length of array we will verify<br/>
59-
* int aLength = ((JSONArray)((JSONObject)JSONParser.parseJSON(ARRAY_OF_JSONOBJECTS)).get("a")).length();<br/>
60-
* // create array of customizations one for each array element<br/>
61-
* RegularExpressionValueMatcher&lt;Object&gt; regExValueMatcher = new RegularExpressionValueMatcher&lt;Object&gt;("\\d+"); // matches one or more digits<br/>
62-
* Customization[] customizations = new Customization[aLength];<br/>
63-
* for (int i=0; i&lt;aLength; i++) {<br/>
64-
* &nbsp;&nbsp;String contextPath = "a["+i+"].id";<br/>
65-
* &nbsp;&nbsp;customizations[i] = new Customization(contextPath, regExValueMatcher);<br/>
66-
* }<br/>
67-
* CustomComparator regExComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, customizations);<br/>
68-
* ArrayValueMatcher&lt;Object&gt; regExArrayValueMatcher = new ArrayValueMatcher&lt;Object&gt;(regExComparator);<br/>
69-
* Customization regExArrayValueCustomization = new Customization("a", regExArrayValueMatcher);<br/>
70-
* CustomComparator regExCustomArrayValueComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, new Customization[] { regExArrayValueCustomization });<br/>
71-
* JSONAssert.assertEquals("{a:[{id:X}]}", ARRAY_OF_JSONOBJECTS, regExCustomArrayValueComparator);<br/>
72-
* </code>
65+
* <pre>{@code
66+
* // get length of array we will verify
67+
* int aLength = ((JSONArray)((JSONObject)JSONParser.parseJSON(ARRAY_OF_JSONOBJECTS)).get("a")).length();
68+
* // create array of customizations one for each array element
69+
* RegularExpressionValueMatcher<Object> regExValueMatcher =
70+
* new RegularExpressionValueMatcher<Object>("\\d+"); // matches one or more digits
71+
* Customization[] customizations = new Customization[aLength];
72+
* for (int i=0; i<aLength; i++) {
73+
* String contextPath = "a["+i+"].id";
74+
* customizations[i] = new Customization(contextPath, regExValueMatcher);
75+
* }
76+
* CustomComparator regExComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, customizations);
77+
* ArrayValueMatcher<Object> regExArrayValueMatcher = new ArrayValueMatcher<Object>(regExComparator);
78+
* Customization regExArrayValueCustomization = new Customization("a", regExArrayValueMatcher);
79+
* CustomComparator regExCustomArrayValueComparator =
80+
* new CustomComparator(JSONCompareMode.STRICT_ORDER, new Customization[] { regExArrayValueCustomization });
81+
* JSONAssert.assertEquals("{a:[{id:X}]}", ARRAY_OF_JSONOBJECTS, regExCustomArrayValueComparator);
82+
* }</pre>
7383
*
7484
* <p>To verify that the 'background' attribute of every element of array 'a' alternates between 'white' and 'grey' starting with first element 'background' being 'white':</p>
7585
*
76-
* <code>
77-
* JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);<br/>
78-
* Customization customization = new Customization("a", new ArrayValueMatcher&lt;Object&gt;(comparator));<br/>
79-
* JSONAssert.assertEquals("{a:[{background:white},{background:grey}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization));
80-
* </code>
86+
* <pre>{@code
87+
* JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
88+
* Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator));
89+
* JSONAssert.assertEquals("{a:[{background:white},{background:grey}]}", ARRAY_OF_JSONOBJECTS,
90+
* new CustomComparator(JSONCompareMode.LENIENT, customization));
91+
* }</pre>
8192
*
8293
* <p>Assuming JSON to be verified is held in String variable ARRAY_OF_JSONARRAYS and contains:</p>
8394
*
@@ -87,23 +98,23 @@
8798
*
8899
* <p>To verify that the first three elements of JSON array 'a' are JSON arrays of length 3:</p>
89100
*
90-
* <code>
91-
* JSONComparator comparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER);<br/>
92-
* Customization customization = new Customization("a", new ArrayValueMatcher&lt;Object&gt;(comparator, 0, 2));<br/>
101+
* <pre>{@code
102+
* JSONComparator comparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER);
103+
* Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 0, 2));
93104
* JSONAssert.assertEquals("{a:[[3]]}", ARRAY_OF_JSONARRAYS, new CustomComparator(JSONCompareMode.LENIENT, customization));
94-
* </code>
105+
* }</pre>
95106
*
96107
* <p>NOTE: simplified expected JSON strings are not possible in this case as ArraySizeComparator does not support them.</p>
97108
*
98109
* <p>To verify that the second elements of JSON array 'a' is a JSON array whose first element has the value 9:</p>
99110
*
100-
* <code>
101-
* JSONComparator innerComparator = new DefaultComparator(JSONCompareMode.LENIENT);<br/>
102-
* Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher&lt;Object&gt;(innerComparator, 0));<br/>
103-
* JSONComparator comparator = new CustomComparator(JSONCompareMode.LENIENT, innerCustomization);<br/>
104-
* Customization customization = new Customization("a", new ArrayValueMatcher&lt;Object&gt;(comparator, 1));<br/>
111+
* <pre>{@code
112+
* JSONComparator innerComparator = new DefaultComparator(JSONCompareMode.LENIENT);
113+
* Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher<Object>(innerComparator, 0));
114+
* JSONComparator comparator = new CustomComparator(JSONCompareMode.LENIENT, innerCustomization);
115+
* Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 1));
105116
* JSONAssert.assertEquals("{a:[[9]]}", ARRAY_OF_JSONARRAYS, new CustomComparator(JSONCompareMode.LENIENT, customization));
106-
* </code>
117+
* }</pre>
107118
*
108119
* <p>To simplify complexity of expected JSON string, the value <code>"{a:[[9]]}"</code> may be replaced by <code>"{a:[9]}"</code> or <code>"{a:9}"</code></p>
109120
*

0 commit comments

Comments
 (0)