File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1383,7 +1383,9 @@ public boolean similar(Object other) {
13831383 return false ;
13841384 }
13851385 } else if (valueThis instanceof Number && valueOther instanceof Number ) {
1386- return JSONObject .isNumberSimilar ((Number )valueThis , (Number )valueOther );
1386+ if (!JSONObject .isNumberSimilar ((Number )valueThis , (Number )valueOther )) {
1387+ return false ;
1388+ }
13871389 } else if (!valueThis .equals (valueOther )) {
13881390 return false ;
13891391 }
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ public class JSONArrayTest {
8787 @ Test
8888 public void verifySimilar () {
8989 final String string1 = "HasSameRef" ;
90+ final String string2 = "HasDifferentRef" ;
9091 JSONArray obj1 = new JSONArray ()
9192 .put ("abc" )
9293 .put (string1 )
@@ -101,10 +102,20 @@ public void verifySimilar() {
101102 .put ("abc" )
102103 .put (new String (string1 ))
103104 .put (2 );
105+
106+ JSONArray obj4 = new JSONArray ()
107+ .put ("abc" )
108+ .put (2.0 )
109+ .put (new String (string1 ));
110+
111+ JSONArray obj5 = new JSONArray ()
112+ .put ("abc" )
113+ .put (2.0 )
114+ .put (new String (string2 ));
104115
105- assertFalse ("Should eval to false" , obj1 .similar (obj2 ));
106-
107- assertTrue ( " Should eval to true " , obj1 .similar (obj3 ));
116+ assertFalse ("obj1-obj2 Should eval to false" , obj1 .similar (obj2 ));
117+ assertTrue ( "obj1-obj3 Should eval to true" , obj1 . similar ( obj3 ));
118+ assertFalse ( "obj4-obj5 Should eval to false " , obj4 .similar (obj5 ));
108119 }
109120
110121 /**
You can’t perform that action at this time.
0 commit comments