@Test
public void testSwitchWhenOuterCompleteBeforeInner() {

    Observable<Observable<String>> source = Observable.create(new Observable.OnSubscribeFunc<Observable<String>>() {
        @Override
        public Subscription onSubscribe(Observer<? super Observable<String>> observer) {
            publishNext(observer, 50, Observable.create(new Observable.OnSubscribeFunc<String>() {
                @Override
                public Subscription onSubscribe(Observer<? super String> observer) {
                    publishNext(observer, 70, "one");
                    publishNext(observer, 100, "two");
                    publishCompleted(observer, 200);
                    return Subscriptions.empty();
                }
            }));
            publishCompleted(observer, 60);
            return Subscriptions.empty();
        }
    });
    Observable<String> sampled = Observable.create(OperationSwitch.switchDo(source));
    sampled.subscribe(observer);
    InOrder inOrder = inOrder(observer);
    scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(2)).onNext(anyString());
    inOrder.verify(observer, times(1)).onCompleted();
}