Skip to content

Commit

Permalink
solved issue skyscreamer#107
Browse files Browse the repository at this point in the history
  • Loading branch information
whitecat315 authored Apr 25, 2021
1 parent 523009b commit 76b03c4
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/main/java/org/skyscreamer/jsonassert/JSONCompare.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
*/

package org.skyscreamer.jsonassert;

Expand All @@ -37,39 +37,40 @@ private static JSONComparator getComparatorForMode(JSONCompareMode mode) {
/**
* Compares JSON string provided to the expected JSON string using provided comparator, and returns the results of
* the comparison.
*
* @param expectedStr Expected JSON string
* @param actualStr JSON string to compare
* @param comparator Comparator to use
* @param actualStr JSON string to compare
* @param comparator Comparator to use
* @return result of the comparison
* @throws JSONException JSON parsing error
* @throws JSONException JSON parsing error
* @throws IllegalArgumentException when type of expectedStr doesn't match the type of actualStr
*/
public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator)
throws JSONException {
SpecialCompareChange scc = new SpecialCompareChange();
expectedStr = scc.change(expectedStr);
actualStr = scc.change(actualStr);
Object expected = JSONParser.parseJSON(expectedStr);
Object actual = JSONParser.parseJSON(actualStr);
if ((expected instanceof JSONObject) && (actual instanceof JSONObject)) {
return compareJSON((JSONObject) expected, (JSONObject) actual, comparator);
}
else if ((expected instanceof JSONArray) && (actual instanceof JSONArray)) {
return compareJSON((JSONArray)expected, (JSONArray)actual, comparator);
}
else if (expected instanceof JSONString && actual instanceof JSONString) {
} else if ((expected instanceof JSONArray) && (actual instanceof JSONArray)) {
return compareJSON((JSONArray) expected, (JSONArray) actual, comparator);
} else if (expected instanceof JSONString && actual instanceof JSONString) {
return compareJson((JSONString) expected, (JSONString) actual);
}
else if (expected instanceof JSONObject) {
} else if (expected instanceof JSONObject) {
return new JSONCompareResult().fail("", expected, actual);
}
else {
} else {
return new JSONCompareResult().fail("", expected, actual);
}
}

/**
/**
* Compares JSON object provided to the expected JSON object using provided comparator, and returns the results of
* the comparison.
* @param expected expected json object
* @param actual actual json object
*
* @param expected expected json object
* @param actual actual json object
* @param comparator comparator to use
* @return result of the comparison
* @throws JSONException JSON parsing error
Expand All @@ -82,8 +83,9 @@ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actu
/**
* Compares JSON object provided to the expected JSON object using provided comparator, and returns the results of
* the comparison.
* @param expected expected json array
* @param actual actual json array
*
* @param expected expected json array
* @param actual actual json array
* @param comparator comparator to use
* @return result of the comparison
* @throws JSONException JSON parsing error
Expand All @@ -106,7 +108,7 @@ public static JSONCompareResult compareJson(final JSONString expected, final JSO
final String expectedJson = expected.toJSONString();
final String actualJson = actual.toJSONString();
if (!expectedJson.equals(actualJson)) {
result.fail("");
result.fail("");
}
return result;
}
Expand Down

0 comments on commit 76b03c4

Please sign in to comment.