18
18
19
19
import static org .mockito .Matchers .any ;
20
20
import static org .mockito .Mockito .*;
21
+ import static org .junit .Assert .*;
21
22
22
23
import java .util .*;
23
24
@@ -31,65 +32,65 @@ public class NotificationTest {
31
32
public void testOnNextIntegerNotificationDoesNotEqualNullNotification (){
32
33
final Notification <Integer > integerNotification = Notification .createOnNext (1 );
33
34
final Notification <Integer > nullNotification = Notification .createOnNext (null );
34
- Assert . assertFalse (integerNotification .equals (nullNotification ));
35
+ assertFalse (integerNotification .equals (nullNotification ));
35
36
}
36
37
37
38
@ Test
38
39
public void testOnNextNullNotificationDoesNotEqualIntegerNotification (){
39
40
final Notification <Integer > integerNotification = Notification .createOnNext (1 );
40
41
final Notification <Integer > nullNotification = Notification .createOnNext (null );
41
- Assert . assertFalse (nullNotification .equals (integerNotification ));
42
+ assertFalse (nullNotification .equals (integerNotification ));
42
43
}
43
44
44
45
@ Test
45
46
public void testOnNextIntegerNotificationsWhenEqual (){
46
47
final Notification <Integer > integerNotification = Notification .createOnNext (1 );
47
48
final Notification <Integer > integerNotification2 = Notification .createOnNext (1 );
48
- Assert . assertTrue (integerNotification .equals (integerNotification2 ));
49
+ assertTrue (integerNotification .equals (integerNotification2 ));
49
50
}
50
51
51
52
@ Test
52
53
public void testOnNextIntegerNotificationsWhenNotEqual (){
53
54
final Notification <Integer > integerNotification = Notification .createOnNext (1 );
54
55
final Notification <Integer > integerNotification2 = Notification .createOnNext (2 );
55
- Assert . assertFalse (integerNotification .equals (integerNotification2 ));
56
+ assertFalse (integerNotification .equals (integerNotification2 ));
56
57
}
57
58
58
59
@ Test
59
60
public void testOnErrorIntegerNotificationDoesNotEqualNullNotification (){
60
61
final Notification <Integer > integerNotification = Notification .createOnError (new Exception ());
61
62
final Notification <Integer > nullNotification = Notification .createOnError (null );
62
- Assert . assertFalse (integerNotification .equals (nullNotification ));
63
+ assertFalse (integerNotification .equals (nullNotification ));
63
64
}
64
65
65
66
@ Test
66
67
public void testOnErrorNullNotificationDoesNotEqualIntegerNotification (){
67
68
final Notification <Integer > integerNotification = Notification .createOnError (new Exception ());
68
69
final Notification <Integer > nullNotification = Notification .createOnError (null );
69
- Assert . assertFalse (nullNotification .equals (integerNotification ));
70
+ assertFalse (nullNotification .equals (integerNotification ));
70
71
}
71
72
72
73
@ Test
73
74
public void testOnErrorIntegerNotificationsWhenEqual (){
74
75
final Exception exception = new Exception ();
75
76
final Notification <Integer > onErrorNotification = Notification .createOnError (exception );
76
77
final Notification <Integer > onErrorNotification2 = Notification .createOnError (exception );
77
- Assert . assertTrue (onErrorNotification .equals (onErrorNotification2 ));
78
+ assertTrue (onErrorNotification .equals (onErrorNotification2 ));
78
79
}
79
80
80
81
@ Test
81
82
public void testOnErrorIntegerNotificationWhenNotEqual (){
82
83
final Notification <Integer > onErrorNotification = Notification .createOnError (new Exception ());
83
84
final Notification <Integer > onErrorNotification2 = Notification .createOnError (new Exception ());
84
- Assert . assertFalse (onErrorNotification .equals (onErrorNotification2 ));
85
+ assertFalse (onErrorNotification .equals (onErrorNotification2 ));
85
86
}
86
87
87
88
@ Test
88
89
public void createWithClass () {
89
90
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 ());
93
94
}
94
95
95
96
@ Test
@@ -121,9 +122,9 @@ static String stripAt(String s) {
121
122
122
123
@ Test
123
124
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 ()));
127
128
}
128
129
129
130
@ Test
@@ -134,7 +135,7 @@ public void hashCodeWorks() {
134
135
Notification <Integer > e1 = Notification .createOnError (new TestException ());
135
136
Notification <Integer > c1 = Notification .createOnCompleted ();
136
137
137
- Assert . assertEquals (n1 .hashCode (), n1a .hashCode ());
138
+ assertEquals (n1 .hashCode (), n1a .hashCode ());
138
139
139
140
Set <Notification <Integer >> set = new HashSet <Notification <Integer >>();
140
141
@@ -143,11 +144,11 @@ public void hashCodeWorks() {
143
144
set .add (e1 );
144
145
set .add (c1 );
145
146
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 ));
151
152
}
152
153
153
154
@ Test
@@ -164,27 +165,27 @@ public void equalsWorks() {
164
165
Notification <Integer > c1 = Notification .createOnCompleted ();
165
166
Notification <Integer > c2 = Notification .createOnCompleted ();
166
167
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 );
170
171
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 );
177
178
178
- Assert . assertEquals (e1 , e1 );
179
- Assert . assertEquals (e1 , e2 );
179
+ assertEquals (e1 , e1 );
180
+ assertNotEquals (e1 , e2 );
180
181
181
- Assert . assertEquals (c1 , c2 );
182
+ assertEquals (c1 , c2 );
182
183
183
- Assert . assertFalse (n1 .equals (null ));
184
- Assert . assertFalse (n1 .equals (1 ));
184
+ assertFalse (n1 .equals (null ));
185
+ assertFalse (n1 .equals (1 ));
185
186
186
- Assert . assertEquals (z1a , z1 );
187
- Assert . assertEquals (z1 , z1a );
187
+ assertEquals (z1a , z1 );
188
+ assertEquals (z1 , z1a );
188
189
}
189
190
190
191
@ Test
@@ -195,25 +196,64 @@ public void contentChecks() {
195
196
Notification <Integer > e2 = Notification .createOnError (null );
196
197
Notification <Integer > c1 = Notification .createOnCompleted ();
197
198
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 ());
201
202
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 ());
205
206
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 ());
209
210
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 ());
213
214
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 ());
217
218
218
219
}
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
+ }
219
259
}
0 commit comments