1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

Merge pull request #81 from johnjaylward/FixFalsePositiveSimilar

Test cases to verify Similar methods
This commit is contained in:
Sean Leary 2017-11-11 16:12:26 -06:00 committed by GitHub
commit 77d142d494
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package org.json.junit; package org.json.junit;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -54,6 +55,32 @@ public class JSONArrayTest {
"\"-1\""+ "\"-1\""+
"]"; "]";
/**
* Tests that the similar method is working as expected.
*/
@Test
public void verifySimilar() {
final String string1 = "HasSameRef";
JSONArray obj1 = new JSONArray()
.put("abc")
.put(string1)
.put(2);
JSONArray obj2 = new JSONArray()
.put("abc")
.put(string1)
.put(3);
JSONArray obj3 = new JSONArray()
.put("abc")
.put(new String(string1))
.put(2);
assertFalse("Should eval to false", obj1.similar(obj2));
assertTrue("Should eval to true", obj1.similar(obj3));
}
/** /**
* Attempt to create a JSONArray with a null string. * Attempt to create a JSONArray with a null string.
* Expects a NullPointerException. * Expects a NullPointerException.

View file

@ -58,6 +58,33 @@ import com.jayway.jsonpath.JsonPath;
* otherwise be impossible. * otherwise be impossible.
*/ */
public class JSONObjectTest { public class JSONObjectTest {
/**
* Tests that the similar method is working as expected.
*/
@Test
public void verifySimilar() {
final String string1 = "HasSameRef";
JSONObject obj1 = new JSONObject()
.put("key1", "abc")
.put("key2", 2)
.put("key3", string1);
JSONObject obj2 = new JSONObject()
.put("key1", "abc")
.put("key2", 3)
.put("key3", string1);
JSONObject obj3 = new JSONObject()
.put("key1", "abc")
.put("key2", 2)
.put("key3", new String(string1));
assertFalse("Should eval to false", obj1.similar(obj2));
assertTrue("Should eval to true", obj1.similar(obj3));
}
/** /**
* JSONObject built from a bean, but only using a null value. * JSONObject built from a bean, but only using a null value.