2
2
3
3
import org .junit .Test ;
4
4
import org .mockito .Mockito ;
5
- import rx .Observable ;
6
5
import rx .Observer ;
7
6
import rx .Subscription ;
8
7
import rx .subscriptions .Subscriptions ;
8
+ import rx .testing .UnsubscribeTester ;
9
9
import rx .util .functions .Func1 ;
10
10
11
11
import java .util .ArrayList ;
14
14
import java .util .List ;
15
15
import java .util .Map ;
16
16
17
- import static org .junit .Assert .assertTrue ;
18
17
import static org .mockito .Matchers .any ;
19
18
import static org .mockito .Mockito .mock ;
20
19
import static org .mockito .Mockito .times ;
@@ -270,8 +269,8 @@ private void assertObservedUntilTwo(Observer<String> aObserver)
270
269
public void testUnsubscribeFromOnNext () {
271
270
RepeatSubject <Object > subject = RepeatSubject .create ();
272
271
273
- UnsubscribeTest test1 = UnsubscribeTest .createOnNext (subject );
274
- UnsubscribeTest test2 = UnsubscribeTest .createOnNext (subject );
272
+ UnsubscribeTester test1 = UnsubscribeTester .createOnNext (subject );
273
+ UnsubscribeTester test2 = UnsubscribeTester .createOnNext (subject );
275
274
276
275
subject .onNext ("one" );
277
276
@@ -283,8 +282,8 @@ public void testUnsubscribeFromOnNext() {
283
282
public void testUnsubscribeFromOnCompleted () {
284
283
RepeatSubject <Object > subject = RepeatSubject .create ();
285
284
286
- UnsubscribeTest test1 = UnsubscribeTest .createOnCompleted (subject );
287
- UnsubscribeTest test2 = UnsubscribeTest .createOnCompleted (subject );
285
+ UnsubscribeTester test1 = UnsubscribeTester .createOnCompleted (subject );
286
+ UnsubscribeTester test2 = UnsubscribeTester .createOnCompleted (subject );
288
287
289
288
subject .onCompleted ();
290
289
@@ -296,109 +295,14 @@ public void testUnsubscribeFromOnCompleted() {
296
295
public void testUnsubscribeFromOnError () {
297
296
RepeatSubject <Object > subject = RepeatSubject .create ();
298
297
299
- UnsubscribeTest test1 = UnsubscribeTest .createOnError (subject );
300
- UnsubscribeTest test2 = UnsubscribeTest .createOnError (subject );
298
+ UnsubscribeTester test1 = UnsubscribeTester .createOnError (subject );
299
+ UnsubscribeTester test2 = UnsubscribeTester .createOnError (subject );
301
300
302
301
subject .onError (new Exception ());
303
302
304
303
test1 .assertPassed ();
305
304
test2 .assertPassed ();
306
305
}
307
306
308
- private static class UnsubscribeTest
309
- {
310
- private Subscription subscription ;
311
-
312
- private UnsubscribeTest () {}
313
-
314
- public static <T > UnsubscribeTest createOnNext (Observable <T > observable )
315
- {
316
- final UnsubscribeTest test = new UnsubscribeTest ();
317
- test .setSubscription (observable .subscribe (new Observer <T >()
318
- {
319
- @ Override
320
- public void onCompleted ()
321
- {
322
- }
323
-
324
- @ Override
325
- public void onError (Exception e )
326
- {
327
- }
328
-
329
- @ Override
330
- public void onNext (T args )
331
- {
332
- test .doUnsubscribe ();
333
- }
334
- }));
335
- return test ;
336
- }
337
-
338
- public static <T > UnsubscribeTest createOnCompleted (Observable <T > observable )
339
- {
340
- final UnsubscribeTest test = new UnsubscribeTest ();
341
- test .setSubscription (observable .subscribe (new Observer <T >()
342
- {
343
- @ Override
344
- public void onCompleted ()
345
- {
346
- test .doUnsubscribe ();
347
- }
348
-
349
- @ Override
350
- public void onError (Exception e )
351
- {
352
- }
353
-
354
- @ Override
355
- public void onNext (T args )
356
- {
357
- }
358
- }));
359
- return test ;
360
- }
361
-
362
- public static <T > UnsubscribeTest createOnError (Observable <T > observable )
363
- {
364
- final UnsubscribeTest test = new UnsubscribeTest ();
365
- test .setSubscription (observable .subscribe (new Observer <T >()
366
- {
367
- @ Override
368
- public void onCompleted ()
369
- {
370
- }
371
-
372
- @ Override
373
- public void onError (Exception e )
374
- {
375
- test .doUnsubscribe ();
376
- }
377
-
378
- @ Override
379
- public void onNext (T args )
380
- {
381
- }
382
- }));
383
- return test ;
384
- }
385
-
386
- private void setSubscription (Subscription subscription )
387
- {
388
- this .subscription = subscription ;
389
- }
390
-
391
- private void doUnsubscribe ()
392
- {
393
- Subscription subscription = this .subscription ;
394
- this .subscription = null ;
395
- subscription .unsubscribe ();
396
- }
397
-
398
- public void assertPassed ()
399
- {
400
- assertTrue ("expected notification was received" , subscription == null );
401
- }
402
- }
403
307
}
404
308
}
0 commit comments