11package org .skyscreamer .jsonassert .comparator ;
22
3+ import static org .skyscreamer .jsonassert .comparator .JSONCompareUtil .allJSONObjects ;
4+ import static org .skyscreamer .jsonassert .comparator .JSONCompareUtil .allSimpleValues ;
5+
36import org .json .JSONArray ;
47import org .json .JSONException ;
58import org .json .JSONObject ;
69import org .skyscreamer .jsonassert .JSONCompareMode ;
710import org .skyscreamer .jsonassert .JSONCompareResult ;
811
9- import static org .skyscreamer .jsonassert .comparator .JSONCompareUtil .allJSONObjects ;
10- import static org .skyscreamer .jsonassert .comparator .JSONCompareUtil .allSimpleValues ;
11-
1212/**
1313 * This class is the default json comparator implementation. <p/>
14- * Comparison is performed according to {@link JSONCompareMode} that is passed as constructor's argument.
14+ * Comparison is performed according to {@link JSONCompareMode} that is passed as constructor's argument.
1515 */
1616public class DefaultComparator extends AbstractComparator {
1717
@@ -36,8 +36,8 @@ public void compareJSON(String prefix, JSONObject expected, JSONObject actual, J
3636 @ Override
3737 public void compareValues (String prefix , Object expectedValue , Object actualValue , JSONCompareResult result )
3838 throws JSONException {
39- if (expectedValue instanceof Number && actualValue instanceof Number ) {
40- if ((( Number ) expectedValue ). doubleValue () != (( Number ) actualValue ). doubleValue ( )) {
39+ if (areNumbers ( expectedValue , actualValue ) ) {
40+ if (areSameDoubles ( expectedValue , actualValue )) {
4141 result .fail (prefix , expectedValue , actualValue );
4242 }
4343 } else if (expectedValue .getClass ().isAssignableFrom (actualValue .getClass ())) {
@@ -74,4 +74,12 @@ public void compareJSONArray(String prefix, JSONArray expected, JSONArray actual
7474 recursivelyCompareJSONArray (prefix , expected , actual , result );
7575 }
7676 }
77+
78+ private boolean areNumbers (Object expectedValue , Object actualValue ) {
79+ return expectedValue instanceof Number && actualValue instanceof Number ;
80+ }
81+
82+ private boolean areSameDoubles (Object expectedValue , Object actualValue ) {
83+ return ((Number ) expectedValue ).doubleValue () != ((Number ) actualValue ).doubleValue ();
84+ }
7785}
0 commit comments