1818
1919import static org .mockito .Matchers .any ;
2020import static org .mockito .Mockito .*;
21+ import static org .junit .Assert .*;
2122
2223import java .util .*;
2324
@@ -31,65 +32,65 @@ public class NotificationTest {
3132 public void testOnNextIntegerNotificationDoesNotEqualNullNotification (){
3233 final Notification <Integer > integerNotification = Notification .createOnNext (1 );
3334 final Notification <Integer > nullNotification = Notification .createOnNext (null );
34- Assert . assertFalse (integerNotification .equals (nullNotification ));
35+ assertFalse (integerNotification .equals (nullNotification ));
3536 }
3637
3738 @ Test
3839 public void testOnNextNullNotificationDoesNotEqualIntegerNotification (){
3940 final Notification <Integer > integerNotification = Notification .createOnNext (1 );
4041 final Notification <Integer > nullNotification = Notification .createOnNext (null );
41- Assert . assertFalse (nullNotification .equals (integerNotification ));
42+ assertFalse (nullNotification .equals (integerNotification ));
4243 }
4344
4445 @ Test
4546 public void testOnNextIntegerNotificationsWhenEqual (){
4647 final Notification <Integer > integerNotification = Notification .createOnNext (1 );
4748 final Notification <Integer > integerNotification2 = Notification .createOnNext (1 );
48- Assert . assertTrue (integerNotification .equals (integerNotification2 ));
49+ assertTrue (integerNotification .equals (integerNotification2 ));
4950 }
5051
5152 @ Test
5253 public void testOnNextIntegerNotificationsWhenNotEqual (){
5354 final Notification <Integer > integerNotification = Notification .createOnNext (1 );
5455 final Notification <Integer > integerNotification2 = Notification .createOnNext (2 );
55- Assert . assertFalse (integerNotification .equals (integerNotification2 ));
56+ assertFalse (integerNotification .equals (integerNotification2 ));
5657 }
5758
5859 @ Test
5960 public void testOnErrorIntegerNotificationDoesNotEqualNullNotification (){
6061 final Notification <Integer > integerNotification = Notification .createOnError (new Exception ());
6162 final Notification <Integer > nullNotification = Notification .createOnError (null );
62- Assert . assertFalse (integerNotification .equals (nullNotification ));
63+ assertFalse (integerNotification .equals (nullNotification ));
6364 }
6465
6566 @ Test
6667 public void testOnErrorNullNotificationDoesNotEqualIntegerNotification (){
6768 final Notification <Integer > integerNotification = Notification .createOnError (new Exception ());
6869 final Notification <Integer > nullNotification = Notification .createOnError (null );
69- Assert . assertFalse (nullNotification .equals (integerNotification ));
70+ assertFalse (nullNotification .equals (integerNotification ));
7071 }
7172
7273 @ Test
7374 public void testOnErrorIntegerNotificationsWhenEqual (){
7475 final Exception exception = new Exception ();
7576 final Notification <Integer > onErrorNotification = Notification .createOnError (exception );
7677 final Notification <Integer > onErrorNotification2 = Notification .createOnError (exception );
77- Assert . assertTrue (onErrorNotification .equals (onErrorNotification2 ));
78+ assertTrue (onErrorNotification .equals (onErrorNotification2 ));
7879 }
7980
8081 @ Test
8182 public void testOnErrorIntegerNotificationWhenNotEqual (){
8283 final Notification <Integer > onErrorNotification = Notification .createOnError (new Exception ());
8384 final Notification <Integer > onErrorNotification2 = Notification .createOnError (new Exception ());
84- Assert . assertFalse (onErrorNotification .equals (onErrorNotification2 ));
85+ assertFalse (onErrorNotification .equals (onErrorNotification2 ));
8586 }
8687
8788 @ Test
8889 public void createWithClass () {
8990 Notification <Integer > n = Notification .createOnCompleted (Integer .class );
90- Assert . assertTrue (n .isOnCompleted ());
91- Assert . assertFalse (n .hasThrowable ());
92- Assert . assertFalse (n .hasValue ());
91+ assertTrue (n .isOnCompleted ());
92+ assertFalse (n .hasThrowable ());
93+ assertFalse (n .hasValue ());
9394 }
9495
9596 @ Test
@@ -121,9 +122,9 @@ static String stripAt(String s) {
121122
122123 @ Test
123124 public void toStringVariants () {
124- Assert . assertEquals ("[rx.Notification OnNext 1]" , stripAt (Notification .createOnNext (1 ).toString ()));
125- Assert . assertEquals ("[rx.Notification OnError Forced failure]" , stripAt (Notification .createOnError (new TestException ("Forced failure" )).toString ()));
126- Assert . assertEquals ("[rx.Notification OnCompleted]" , stripAt (Notification .createOnCompleted ().toString ()));
125+ assertEquals ("[rx.Notification OnNext 1]" , stripAt (Notification .createOnNext (1 ).toString ()));
126+ assertEquals ("[rx.Notification OnError Forced failure]" , stripAt (Notification .createOnError (new TestException ("Forced failure" )).toString ()));
127+ assertEquals ("[rx.Notification OnCompleted]" , stripAt (Notification .createOnCompleted ().toString ()));
127128 }
128129
129130 @ Test
@@ -134,7 +135,7 @@ public void hashCodeWorks() {
134135 Notification <Integer > e1 = Notification .createOnError (new TestException ());
135136 Notification <Integer > c1 = Notification .createOnCompleted ();
136137
137- Assert . assertEquals (n1 .hashCode (), n1a .hashCode ());
138+ assertEquals (n1 .hashCode (), n1a .hashCode ());
138139
139140 Set <Notification <Integer >> set = new HashSet <Notification <Integer >>();
140141
@@ -143,11 +144,11 @@ public void hashCodeWorks() {
143144 set .add (e1 );
144145 set .add (c1 );
145146
146- Assert . assertTrue (set .contains (n1 ));
147- Assert . assertTrue (set .contains (n1a ));
148- Assert . assertTrue (set .contains (n2 ));
149- Assert . assertTrue (set .contains (e1 ));
150- Assert . assertTrue (set .contains (c1 ));
147+ assertTrue (set .contains (n1 ));
148+ assertTrue (set .contains (n1a ));
149+ assertTrue (set .contains (n2 ));
150+ assertTrue (set .contains (e1 ));
151+ assertTrue (set .contains (c1 ));
151152 }
152153
153154 @ Test
@@ -164,27 +165,27 @@ public void equalsWorks() {
164165 Notification <Integer > c1 = Notification .createOnCompleted ();
165166 Notification <Integer > c2 = Notification .createOnCompleted ();
166167
167- Assert . assertEquals (n1 , n1a );
168- Assert . assertNotEquals (n1 , n2 );
169- Assert . assertNotEquals (n2 , n1 );
168+ assertEquals (n1 , n1a );
169+ assertNotEquals (n1 , n2 );
170+ assertNotEquals (n2 , n1 );
170171
171- Assert . assertNotEquals (n1 , e1 );
172- Assert . assertNotEquals (e1 , n1 );
173- Assert . assertNotEquals (e1 , c1 );
174- Assert . assertNotEquals (n1 , c1 );
175- Assert . assertNotEquals (c1 , n1 );
176- Assert . assertNotEquals (c1 , e1 );
172+ assertNotEquals (n1 , e1 );
173+ assertNotEquals (e1 , n1 );
174+ assertNotEquals (e1 , c1 );
175+ assertNotEquals (n1 , c1 );
176+ assertNotEquals (c1 , n1 );
177+ assertNotEquals (c1 , e1 );
177178
178- Assert . assertEquals (e1 , e1 );
179- Assert . assertEquals (e1 , e2 );
179+ assertEquals (e1 , e1 );
180+ assertNotEquals (e1 , e2 );
180181
181- Assert . assertEquals (c1 , c2 );
182+ assertEquals (c1 , c2 );
182183
183- Assert . assertFalse (n1 .equals (null ));
184- Assert . assertFalse (n1 .equals (1 ));
184+ assertFalse (n1 .equals (null ));
185+ assertFalse (n1 .equals (1 ));
185186
186- Assert . assertEquals (z1a , z1 );
187- Assert . assertEquals (z1 , z1a );
187+ assertEquals (z1a , z1 );
188+ assertEquals (z1 , z1a );
188189 }
189190
190191 @ Test
@@ -195,25 +196,64 @@ public void contentChecks() {
195196 Notification <Integer > e2 = Notification .createOnError (null );
196197 Notification <Integer > c1 = Notification .createOnCompleted ();
197198
198- Assert . assertFalse (z1 .hasValue ());
199- Assert . assertFalse (z1 .hasThrowable ());
200- Assert . assertFalse (z1 .isOnCompleted ());
199+ assertFalse (z1 .hasValue ());
200+ assertFalse (z1 .hasThrowable ());
201+ assertFalse (z1 .isOnCompleted ());
201202
202- Assert . assertTrue (n1 .hasValue ());
203- Assert . assertFalse (n1 .hasThrowable ());
204- Assert . assertFalse (n1 .isOnCompleted ());
203+ assertTrue (n1 .hasValue ());
204+ assertFalse (n1 .hasThrowable ());
205+ assertFalse (n1 .isOnCompleted ());
205206
206- Assert . assertFalse (e1 .hasValue ());
207- Assert . assertTrue (e1 .hasThrowable ());
208- Assert . assertFalse (e1 .isOnCompleted ());
207+ assertFalse (e1 .hasValue ());
208+ assertTrue (e1 .hasThrowable ());
209+ assertFalse (e1 .isOnCompleted ());
209210
210- Assert . assertFalse (e2 .hasValue ());
211- Assert . assertFalse (e2 .hasThrowable ());
212- Assert . assertFalse (e2 .isOnCompleted ());
211+ assertFalse (e2 .hasValue ());
212+ assertFalse (e2 .hasThrowable ());
213+ assertFalse (e2 .isOnCompleted ());
213214
214- Assert . assertFalse (c1 .hasValue ());
215- Assert . assertFalse (c1 .hasThrowable ());
216- Assert . assertTrue (c1 .isOnCompleted ());
215+ assertFalse (c1 .hasValue ());
216+ assertFalse (c1 .hasThrowable ());
217+ assertTrue (c1 .isOnCompleted ());
217218
218219 }
220+
221+ @ Test
222+ public void exceptionEquality () {
223+ EqualException ex1 = new EqualException ("1" );
224+ EqualException ex2 = new EqualException ("1" );
225+ EqualException ex3 = new EqualException ("3" );
226+
227+ Notification <Integer > e1 = Notification .createOnError (ex1 );
228+ Notification <Integer > e2 = Notification .createOnError (ex2 );
229+ Notification <Integer > e3 = Notification .createOnError (ex3 );
230+
231+ assertEquals (e1 , e1 );
232+ assertEquals (e1 , e2 );
233+ assertEquals (e2 , e1 );
234+ assertEquals (e2 , e2 );
235+
236+ assertNotEquals (e1 , e3 );
237+ assertNotEquals (e2 , e3 );
238+ assertNotEquals (e3 , e1 );
239+ assertNotEquals (e3 , e2 );
240+ }
241+
242+ static final class EqualException extends RuntimeException {
243+
244+ /** */
245+ private static final long serialVersionUID = 446310455393317050L ;
246+
247+ public EqualException (String message ) {
248+ super (message );
249+ }
250+
251+ @ Override
252+ public boolean equals (Object o ) {
253+ if (o instanceof EqualException ) {
254+ return getMessage ().equals (((EqualException )o ).getMessage ());
255+ }
256+ return false ;
257+ }
258+ }
219259}
0 commit comments