@Override public void subscribe(Subscriber<? super String> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); boolean errorThrown = false; for (String s : valuesToReturn) { if (s == null) { System.out.println("throwing exception"); observer.onError(new NullPointerException()); errorThrown = true; // purposefully not returning here so it will continue calling onNext // so that we also test that we handle bad sequences like this } else { observer.onNext(s); } } if (!errorThrown) { observer.onComplete(); } }
@Override public void subscribe(Subscriber<? super String> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); observer.onNext("hello"); observer.onComplete(); }