mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
Fixes Issue #611 JsonObject.similar() returns after number entry check
This commit is contained in:
parent
449ec8745e
commit
cfbc306673
@ -2092,7 +2092,9 @@ public class JSONObject {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (valueThis instanceof Number && valueOther instanceof Number) {
|
} else if (valueThis instanceof Number && valueOther instanceof Number) {
|
||||||
return isNumberSimilar((Number)valueThis, (Number)valueOther);
|
if (!isNumberSimilar((Number)valueThis, (Number)valueOther)) {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
} else if (!valueThis.equals(valueOther)) {
|
} else if (!valueThis.equals(valueOther)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ public class JSONObjectTest {
|
|||||||
@Test
|
@Test
|
||||||
public void verifySimilar() {
|
public void verifySimilar() {
|
||||||
final String string1 = "HasSameRef";
|
final String string1 = "HasSameRef";
|
||||||
|
final String string2 = "HasDifferentRef";
|
||||||
JSONObject obj1 = new JSONObject()
|
JSONObject obj1 = new JSONObject()
|
||||||
.put("key1", "abc")
|
.put("key1", "abc")
|
||||||
.put("key2", 2)
|
.put("key2", 2)
|
||||||
@ -119,12 +120,16 @@ public class JSONObjectTest {
|
|||||||
.put("key1", "abc")
|
.put("key1", "abc")
|
||||||
.put("key2", 2.0)
|
.put("key2", 2.0)
|
||||||
.put("key3", new String(string1));
|
.put("key3", new String(string1));
|
||||||
|
|
||||||
assertFalse("Should eval to false", obj1.similar(obj2));
|
|
||||||
|
|
||||||
assertTrue("Should eval to true", obj1.similar(obj3));
|
JSONObject obj5 = new JSONObject()
|
||||||
|
.put("key1", "abc")
|
||||||
|
.put("key2", 2.0)
|
||||||
|
.put("key3", new String(string2));
|
||||||
|
|
||||||
assertTrue("Should eval to true", obj1.similar(obj4));
|
assertFalse("obj1-obj2 Should eval to false", obj1.similar(obj2));
|
||||||
|
assertTrue("obj1-obj3 Should eval to true", obj1.similar(obj3));
|
||||||
|
assertTrue("obj1-obj4 Should eval to true", obj1.similar(obj4));
|
||||||
|
assertFalse("obj1-obj5 Should eval to false", obj1.similar(obj5));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user