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 1
1
package org .json .junit ;
2
2
3
3
import static org .junit .Assert .assertEquals ;
4
+ import static org .junit .Assert .assertFalse ;
4
5
import static org .junit .Assert .assertNull ;
5
6
import static org .junit .Assert .assertTrue ;
6
7
@@ -54,6 +55,32 @@ public class JSONArrayTest {
54
55
"\" -1\" " +
55
56
"]" ;
56
57
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
+
57
84
/**
58
85
* Attempt to create a JSONArray with a null string.
59
86
* Expects a NullPointerException.
Original file line number Diff line number Diff line change 58
58
* otherwise be impossible.
59
59
*/
60
60
public 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
+ }
61
88
62
89
/**
63
90
* JSONObject built from a bean, but only using a null value.
You can’t perform that action at this time.
0 commit comments