Skip to content

Fix to Notification equals method. #3214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/rx/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ public boolean equals(Object obj) {
return false;
if (hasThrowable() && !getThrowable().equals(notification.getThrowable()))
return false;
if(!hasValue() && !hasThrowable() && notification.hasValue())
return false;
if(!hasValue() && !hasThrowable() && notification.hasThrowable())
return false;

return true;
}
}
64 changes: 64 additions & 0 deletions src/test/java/rx/NotificationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package rx;

import org.junit.Assert;
import org.junit.Test;

public class NotificationTest {

@Test
public void testOnNextIntegerNotificationDoesNotEqualNullNotification(){
final Notification<Integer> integerNotification = Notification.createOnNext(1);
final Notification<Integer> nullNotification = Notification.createOnNext(null);
Assert.assertFalse(integerNotification.equals(nullNotification));
}

@Test
public void testOnNextNullNotificationDoesNotEqualIntegerNotification(){
final Notification<Integer> integerNotification = Notification.createOnNext(1);
final Notification<Integer> nullNotification = Notification.createOnNext(null);
Assert.assertFalse(nullNotification.equals(integerNotification));
}

@Test
public void testOnNextIntegerNotificationsWhenEqual(){
final Notification<Integer> integerNotification = Notification.createOnNext(1);
final Notification<Integer> integerNotification2 = Notification.createOnNext(1);
Assert.assertTrue(integerNotification.equals(integerNotification2));
}

@Test
public void testOnNextIntegerNotificationsWhenNotEqual(){
final Notification<Integer> integerNotification = Notification.createOnNext(1);
final Notification<Integer> integerNotification2 = Notification.createOnNext(2);
Assert.assertFalse(integerNotification.equals(integerNotification2));
}

@Test
public void testOnErrorIntegerNotificationDoesNotEqualNullNotification(){
final Notification<Integer> integerNotification = Notification.createOnError(new Exception());
final Notification<Integer> nullNotification = Notification.createOnError(null);
Assert.assertFalse(integerNotification.equals(nullNotification));
}

@Test
public void testOnErrorNullNotificationDoesNotEqualIntegerNotification(){
final Notification<Integer> integerNotification = Notification.createOnError(new Exception());
final Notification<Integer> nullNotification = Notification.createOnError(null);
Assert.assertFalse(nullNotification.equals(integerNotification));
}

@Test
public void testOnErrorIntegerNotificationsWhenEqual(){
final Exception exception = new Exception();
final Notification<Integer> onErrorNotification = Notification.createOnError(exception);
final Notification<Integer> onErrorNotification2 = Notification.createOnError(exception);
Assert.assertTrue(onErrorNotification.equals(onErrorNotification2));
}

@Test
public void testOnErrorIntegerNotificationWhenNotEqual(){
final Notification<Integer> onErrorNotification = Notification.createOnError(new Exception());
final Notification<Integer> onErrorNotification2 = Notification.createOnError(new Exception());
Assert.assertFalse(onErrorNotification.equals(onErrorNotification2));
}
}