Skip to content

Commit ac82aee

Browse files
committed
Fix bug where actual and expected were reversed
1 parent 3d25774 commit ac82aee

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package org.skyscreamer.jsonassert;
22

3+
import java.util.ArrayList;
4+
import java.util.HashMap;
5+
import java.util.HashSet;
6+
import java.util.Iterator;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.Set;
10+
import java.util.TreeSet;
11+
312
import org.apache.commons.collections.CollectionUtils;
413
import org.json.JSONArray;
514
import org.json.JSONException;
615
import org.json.JSONObject;
716

8-
import java.util.*;
9-
1017
/**
1118
* Provides the logic to compare two JSON entities. This is the backend to {@link JSONAssert}, but it can
1219
* be programmed against directly to access the functionality. (eg, to make something that works with a
@@ -201,14 +208,14 @@ private static void recursivelyCompareJSONArray(String key, JSONArray expected,
201208
continue;
202209
}
203210
if (actualElement instanceof JSONObject) {
204-
if (compareJSON((JSONObject)actualElement, (JSONObject)expected.get(j), mode).passed()) {
211+
if (compareJSON((JSONObject)expected.get(j), (JSONObject)actualElement, mode).passed()) {
205212
matched.add(j);
206213
matchFound = true;
207214
break;
208215
}
209216
}
210217
else if (actualElement instanceof JSONArray) {
211-
if (compareJSON((JSONArray)actualElement, (JSONArray)expected.get(j), mode).passed()) {
218+
if (compareJSON((JSONArray)expected.get(j), (JSONArray)actualElement, mode).passed()) {
212219
matched.add(j);
213220
matchFound = true;
214221
break;

src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package org.skyscreamer.jsonassert;
22

3+
import static org.skyscreamer.jsonassert.JSONCompareMode.LENIENT;
4+
import static org.skyscreamer.jsonassert.JSONCompareMode.STRICT;
5+
36
import org.json.JSONException;
47
import org.junit.Assert;
58
import org.junit.Test;
69

7-
import static org.skyscreamer.jsonassert.JSONCompareMode.*;
8-
910
/**
1011
* Unit tests for {@link JSONAssert}
1112
*/
@@ -135,7 +136,12 @@ public void testArrayOfArraysStrict() throws JSONException {
135136
public void testArrayOfArrays() throws JSONException {
136137
testPass("{id:1,stuff:[[4,3],[3,2],[],[1,2]]}", "{id:1,stuff:[[1,2],[2,3],[],[3,4]]}", false);
137138
}
138-
139+
140+
@Test
141+
public void testLenientArrayRecursion() throws JSONException {
142+
testPass("[{\"arr\":[5, 2, 1]}]", "[{\"b\":3, \"arr\":[1, 5, 2]}]", false);
143+
}
144+
139145
private void testPass(String expected, String actual, boolean strict)
140146
throws JSONException
141147
{

0 commit comments

Comments
 (0)