Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cases to verify Similar methods #81

Merged
merged 2 commits into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/test/java/org/json/junit/JSONArrayTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.json.junit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -54,6 +55,32 @@ public class JSONArrayTest {
"\"-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.
* Expects a NullPointerException.
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/org/json/junit/JSONObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@
* otherwise be impossible.
*/
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.
Expand Down