@@ -357,6 +357,56 @@ public void call(Long v) {
357
357
Assert .assertEquals (Arrays .asList (5L , 1L , 1L , 1L , 1L , 1L , 1L , 1L , 1L , 1L , 1L ), requested );
358
358
}
359
359
360
+ @ Test
361
+ public void andThen () {
362
+ TestSubscriber <String > ts = new TestSubscriber <>(0 );
363
+ Completable .complete ().andThen (Observable .just ("foo" )).subscribe (ts );
364
+ ts .requestMore (1 );
365
+ ts .assertValue ("foo" );
366
+ ts .assertCompleted ();
367
+ ts .assertNoErrors ();
368
+ }
369
+
370
+ @ Test
371
+ public void andThenNever () {
372
+ TestSubscriber <String > ts = new TestSubscriber <>(0 );
373
+ Completable .never ().andThen (Observable .just ("foo" )).subscribe (ts );
374
+ ts .requestMore (1 );
375
+ ts .assertNoValues ();
376
+ ts .assertNoTerminalEvent ();
377
+ }
378
+
379
+ @ Test
380
+ public void andThenError () {
381
+ TestSubscriber <String > ts = new TestSubscriber <>(0 );
382
+ AtomicBoolean hasRun = new AtomicBoolean (false );
383
+ Exception e = new Exception ();
384
+ Completable .create (cs -> cs .onError (e ))
385
+ .andThen (Observable .<String >create (s -> {
386
+ hasRun .set (true );
387
+ s .onNext ("foo" );
388
+ s .onCompleted ();
389
+ }))
390
+ .subscribe (ts );
391
+ ts .assertNoValues ();
392
+ ts .assertError (e );
393
+ Assert .assertFalse ("Should not have subscribed to observable when completable errors" , hasRun .get ());
394
+ }
395
+
396
+ @ Test
397
+ public void andThenSubscribeOn () {
398
+ TestSubscriber <String > ts = new TestSubscriber <>(0 );
399
+ TestScheduler scheduler = new TestScheduler ();
400
+ Completable .complete ().andThen (Observable .just ("foo" ).delay (1 , TimeUnit .SECONDS , scheduler )).subscribe (ts );
401
+ ts .requestMore (1 );
402
+ ts .assertNoValues ();
403
+ ts .assertNoTerminalEvent ();
404
+ scheduler .advanceTimeBy (1 , TimeUnit .SECONDS );
405
+ ts .assertValue ("foo" );
406
+ ts .assertCompleted ();
407
+ ts .assertNoErrors ();
408
+ }
409
+
360
410
@ Test (expected = NullPointerException .class )
361
411
public void createNull () {
362
412
Completable .create (null );
0 commit comments