File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
src/test/java/org/json/junit Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 11package org .json .junit ;
22
33import static org .junit .Assert .assertEquals ;
4+ import static org .junit .Assert .assertFalse ;
45import static org .junit .Assert .assertNull ;
56import static org .junit .Assert .assertTrue ;
67
@@ -54,6 +55,32 @@ public class JSONArrayTest {
5455 "\" -1\" " +
5556 "]" ;
5657
58+ /**
59+ * Tests that the similar method is working as expected.
60+ */
61+ @ Test
62+ public void verifySimilar () {
63+ final String string1 = "HasSameRef" ;
64+ JSONArray obj1 = new JSONArray ()
65+ .put ("abc" )
66+ .put (string1 )
67+ .put (2 );
68+
69+ JSONArray obj2 = new JSONArray ()
70+ .put ("abc" )
71+ .put (string1 )
72+ .put (3 );
73+
74+ JSONArray obj3 = new JSONArray ()
75+ .put ("abc" )
76+ .put (new String (string1 ))
77+ .put (2 );
78+
79+ assertFalse ("Should eval to false" , obj1 .similar (obj2 ));
80+
81+ assertTrue ("Should eval to true" , obj1 .similar (obj3 ));
82+ }
83+
5784 /**
5885 * Attempt to create a JSONArray with a null string.
5986 * Expects a NullPointerException.
Original file line number Diff line number Diff line change 5858 * otherwise be impossible.
5959 */
6060public class JSONObjectTest {
61+
62+ /**
63+ * Tests that the similar method is working as expected.
64+ */
65+ @ Test
66+ public void verifySimilar () {
67+ final String string1 = "HasSameRef" ;
68+ JSONObject obj1 = new JSONObject ()
69+ .put ("key1" , "abc" )
70+ .put ("key2" , 2 )
71+ .put ("key3" , string1 );
72+
73+ JSONObject obj2 = new JSONObject ()
74+ .put ("key1" , "abc" )
75+ .put ("key2" , 3 )
76+ .put ("key3" , string1 );
77+
78+ JSONObject obj3 = new JSONObject ()
79+ .put ("key1" , "abc" )
80+ .put ("key2" , 2 )
81+ .put ("key3" , new String (string1 ));
82+
83+ assertFalse ("Should eval to false" , obj1 .similar (obj2 ));
84+
85+ assertTrue ("Should eval to true" , obj1 .similar (obj3 ));
86+
87+ }
6188
6289 /**
6390 * JSONObject built from a bean, but only using a null value.
You can’t perform that action at this time.
0 commit comments