Skip to content

Commit 5d27630

Browse files
committed
Fix to Notification equals method.
1 parent 689e73f commit 5d27630

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/main/java/rx/Notification.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ public boolean equals(Object obj) {
202202
return false;
203203
if (hasThrowable() && !getThrowable().equals(notification.getThrowable()))
204204
return false;
205+
if(!hasValue() && !hasThrowable() && notification.hasValue())
206+
return false;
207+
if(!hasValue() && !hasThrowable() && notification.hasThrowable())
208+
return false;
209+
205210
return true;
206211
}
207212
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package rx;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class NotificationTest {
7+
8+
@Test
9+
public void testOnNextIntegerNotificationDoesNotEqualNullNotification(){
10+
final Notification<Integer> integerNotification = Notification.createOnNext(1);
11+
final Notification<Integer> nullNotification = Notification.createOnNext(null);
12+
Assert.assertFalse(integerNotification.equals(nullNotification));
13+
}
14+
15+
@Test
16+
public void testOnNextNullNotificationDoesNotEqualIntegerNotification(){
17+
final Notification<Integer> integerNotification = Notification.createOnNext(1);
18+
final Notification<Integer> nullNotification = Notification.createOnNext(null);
19+
Assert.assertFalse(nullNotification.equals(integerNotification));
20+
}
21+
22+
@Test
23+
public void testOnNextIntegerNotificationsWhenEqual(){
24+
final Notification<Integer> integerNotification = Notification.createOnNext(1);
25+
final Notification<Integer> integerNotification2 = Notification.createOnNext(1);
26+
Assert.assertTrue(integerNotification.equals(integerNotification2));
27+
}
28+
29+
@Test
30+
public void testOnNextIntegerNotificationsWhenNotEqual(){
31+
final Notification<Integer> integerNotification = Notification.createOnNext(1);
32+
final Notification<Integer> integerNotification2 = Notification.createOnNext(2);
33+
Assert.assertFalse(integerNotification.equals(integerNotification2));
34+
}
35+
36+
@Test
37+
public void testOnErrorIntegerNotificationDoesNotEqualNullNotification(){
38+
final Notification<Integer> integerNotification = Notification.createOnError(new Exception());
39+
final Notification<Integer> nullNotification = Notification.createOnError(null);
40+
Assert.assertFalse(integerNotification.equals(nullNotification));
41+
}
42+
43+
@Test
44+
public void testOnErrorNullNotificationDoesNotEqualIntegerNotification(){
45+
final Notification<Integer> integerNotification = Notification.createOnError(new Exception());
46+
final Notification<Integer> nullNotification = Notification.createOnError(null);
47+
Assert.assertFalse(nullNotification.equals(integerNotification));
48+
}
49+
50+
@Test
51+
public void testOnErrorIntegerNotificationsWhenEqual(){
52+
final Exception exception = new Exception();
53+
final Notification<Integer> onErrorNotification = Notification.createOnError(exception);
54+
final Notification<Integer> onErrorNotification2 = Notification.createOnError(exception);
55+
Assert.assertTrue(onErrorNotification.equals(onErrorNotification2));
56+
}
57+
58+
@Test
59+
public void testOnErrorIntegerNotificationWhenNotEqual(){
60+
final Notification<Integer> onErrorNotification = Notification.createOnError(new Exception());
61+
final Notification<Integer> onErrorNotification2 = Notification.createOnError(new Exception());
62+
Assert.assertFalse(onErrorNotification.equals(onErrorNotification2));
63+
}
64+
}

0 commit comments

Comments
 (0)