File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
hamcrest-core/src/main/java/org/hamcrest/core
hamcrest-unit-test/src/main/java/org/hamcrest/core Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -22,16 +22,16 @@ public IsEqual(T equalArg) {
22
22
}
23
23
24
24
public boolean matches (Object arg ) {
25
- return areEqual (object , arg );
25
+ return areEqual (arg , object );
26
26
}
27
27
28
28
public void describeTo (Description description ) {
29
29
description .appendValue (object );
30
30
}
31
31
32
32
private static boolean areEqual (Object o1 , Object o2 ) {
33
- if (o1 == null || o2 == null ) {
34
- return o1 == null && o2 == null ;
33
+ if (o1 == null ) {
34
+ return o2 == null ;
35
35
} else if (isArray (o1 )) {
36
36
return isArray (o2 ) && areArraysEqual (o1 , o2 );
37
37
} else {
Original file line number Diff line number Diff line change @@ -30,6 +30,22 @@ public void testCanCompareNullValues() {
30
30
assertThat ("hi" , not (equalTo (null )));
31
31
}
32
32
33
+ public void testHonoursIsEqualImplementationEvenWithNullValues () {
34
+ Object alwaysEqual = new Object () {
35
+ public boolean equals (Object obj ) {
36
+ return true ;
37
+ }
38
+ };
39
+ Object neverEqual = new Object () {
40
+ public boolean equals (Object obj ) {
41
+ return false ;
42
+ }
43
+ };
44
+
45
+ assertThat (alwaysEqual , equalTo (null ));
46
+ assertThat (neverEqual , not (equalTo (null )));
47
+ }
48
+
33
49
public void testComparesTheElementsOfAnObjectArray () {
34
50
String [] s1 = {"a" , "b" };
35
51
String [] s2 = {"a" , "b" };
You can’t perform that action at this time.
0 commit comments