Search in sources :

Example 1 with FlowableOperator

use of io.reactivex.FlowableOperator in project RxJava by ReactiveX.

the class FlowableSwitchIfEmptyTest method testSwitchTriggerUnsubscribe.

@Test
public void testSwitchTriggerUnsubscribe() throws Exception {
    final BooleanSubscription bs = new BooleanSubscription();
    Flowable<Long> withProducer = Flowable.unsafeCreate(new Publisher<Long>() {

        @Override
        public void subscribe(final Subscriber<? super Long> subscriber) {
            subscriber.onSubscribe(bs);
            subscriber.onNext(42L);
        }
    });
    Flowable.<Long>empty().switchIfEmpty(withProducer).lift(new FlowableOperator<Long, Long>() {

        @Override
        public Subscriber<? super Long> apply(final Subscriber<? super Long> child) {
            return new DefaultSubscriber<Long>() {

                @Override
                public void onComplete() {
                }

                @Override
                public void onError(Throwable e) {
                }

                @Override
                public void onNext(Long aLong) {
                    cancel();
                }
            };
        }
    }).subscribe();
    assertTrue(bs.isCancelled());
// FIXME no longer assertable
//        assertTrue(sub.isUnsubscribed());
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) FlowableOperator(io.reactivex.FlowableOperator) Test(org.junit.Test)

Aggregations

FlowableOperator (io.reactivex.FlowableOperator)1 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)1 Test (org.junit.Test)1