@Override public void onError(Throwable t) { if (done) { RxJavaPlugins.onError(t); return; } done = true; downstream.onError(t); }
@Override public void onError(Throwable t) { Processor<T, T> w = window; if (w != null) { window = null; w.onError(t); } downstream.onError(t); }
@Override public void onError(Throwable t) { if (done) { RxJavaPlugins.onError(t); return; } done = true; downstream.onError(t); }
@Override public void onError(Throwable t) { if (done) { RxJavaPlugins.onError(t); return; } done = true; downstream.onError(t); }
@Override public void onError(Throwable t) { if (done) { RxJavaPlugins.onError(t); return; } done = true; downstream.onError(t); }
public void otherError(Throwable e) { SubscriptionHelper.cancel(upstream); downstream.onError(e); } }
@Override public void onTimeoutError(long idx, Throwable ex) { if (index.compareAndSet(idx, Long.MAX_VALUE)) { SubscriptionHelper.cancel(upstream); downstream.onError(ex); } else { RxJavaPlugins.onError(ex); } }
@Override public void run() { ref.get().onError(ex); } };
@Override public void run() { Subscriber<Object> subscriber = ref.get(); subscriber.onNext(1); subscriber.onError(ex); } };
@Override public void subscribe(Subscriber<? super String> s) { s.onSubscribe(new BooleanSubscription()); subsCount.incrementAndGet(); s.onError(new RuntimeException("failed")); } };
@Override public void onTimeout(long idx) { if (compareAndSet(idx, Long.MAX_VALUE)) { SubscriptionHelper.cancel(upstream); downstream.onError(new TimeoutException(timeoutMessage(timeout, unit))); worker.dispose(); } }
@Test public void testSkipError() { Flowable<Integer> src = Flowable.just(1, 2, 42, 5, 3, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, never()).onNext(anyInt()); inOrder.verify(w, never()).onComplete(); inOrder.verify(w, times(1)).onError(any(RuntimeException.class)); }
@Test public void testSkipEverything() { Flowable<Integer> src = Flowable.just(1, 2, 3, 4, 3, 2, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onError(any(Throwable.class)); verify(w, times(1)).onComplete(); }
@Test public void testTake1() { Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); Flowable<String> take = w.take(2); Subscriber<String> subscriber = TestHelper.mockSubscriber(); take.subscribe(subscriber); verify(subscriber, times(1)).onNext("one"); verify(subscriber, times(1)).onNext("two"); verify(subscriber, never()).onNext("three"); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test public void testSkipEmptyStream() { Flowable<String> w = Flowable.empty(); Flowable<String> skip = w.skip(1); Subscriber<String> subscriber = TestHelper.mockSubscriber(); skip.subscribe(subscriber); verify(subscriber, never()).onNext(any(String.class)); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test public void testSkipTwoElements() { Flowable<String> skip = Flowable.just("one", "two", "three").skip(2); Subscriber<String> subscriber = TestHelper.mockSubscriber(); skip.subscribe(subscriber); verify(subscriber, never()).onNext("one"); verify(subscriber, never()).onNext("two"); verify(subscriber, times(1)).onNext("three"); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test @Ignore("Null values not allowed") public void testSkipLastWithNull() { Flowable<String> flowable = Flowable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); Subscriber<String> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); verify(subscriber, times(1)).onNext("one"); verify(subscriber, times(1)).onNext(null); verify(subscriber, never()).onNext("two"); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test(timeout = 2000) public void testRepeatError() { Subscriber<Object> subscriber = TestHelper.mockSubscriber(); Flowable.error(new TestException()).repeat(10).subscribe(subscriber); verify(subscriber).onError(any(TestException.class)); verify(subscriber, never()).onNext(any()); verify(subscriber, never()).onComplete(); }
@Test public void testSkipError() { Exception e = new Exception(); Flowable<String> ok = Flowable.just("one"); Flowable<String> error = Flowable.error(e); Flowable<String> skip = Flowable.concat(ok, error).skip(100); Subscriber<String> subscriber = TestHelper.mockSubscriber(); skip.subscribe(subscriber); verify(subscriber, never()).onNext(any(String.class)); verify(subscriber, times(1)).onError(e); verify(subscriber, never()).onComplete(); }
@Test public void testSingleOrDefaultWithTooManyElementsFlowable() { Flowable<Integer> flowable = Flowable.just(1, 2).single(3).toFlowable(); Subscriber<Integer> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); InOrder inOrder = inOrder(subscriber); inOrder.verify(subscriber, times(1)).onError( isA(IllegalArgumentException.class)); inOrder.verifyNoMoreInteractions(); }