@Override public Perhaps<Integer> call() throws Exception { if (++counter[0] == 5) { return Perhaps.just(1); } return Perhaps.<Integer>error(new IOException()); } })
@Test public void subscribeThreeArgError() { Perhaps.error(new IOException()).subscribe(this, this, this); assertEquals(1, count); }
@Test public void blockingSubscribeThreeArgError() { Perhaps.error(new IOException()).blockingSubscribe(this, this, this); assertEquals(1, count); }
@Test public void onErrorResumeNextErrorThrows() { Perhaps.<Integer>error(new IOException()) .onErrorResumeNext(new Function<Throwable, Perhaps<Integer>>() { @Override public Perhaps<Integer> apply(Throwable e) throws Exception { throw new IOException(); } }) .test() .assertFailure(CompositeException.class); }
@SuppressWarnings("unchecked") @Test public void mergeIterableError() { Perhaps.merge(Arrays.asList(Perhaps.just(1), Perhaps.error(new IOException()))) .test() .assertFailure(IOException.class, 1); }
@SuppressWarnings("unchecked") @Test public void mergeIterableError2() { Perhaps.merge(Arrays.asList(Perhaps.error(new IOException()), Perhaps.just(2))) .test() .assertFailure(IOException.class); }
@SuppressWarnings("unchecked") @Test public void mergeIterableDelayErrorError() { Perhaps.mergeDelayError(Arrays.asList(Perhaps.just(1), Perhaps.error(new IOException()))) .test() .assertFailure(IOException.class, 1); }
@Test public void mapErrorWithError() { Perhaps.error(new IOException()) .mapError(new Function<Throwable, Throwable>() { @Override public Throwable apply(Throwable t) throws Exception { return new IllegalArgumentException(); } }) .test() .assertFailure(IllegalArgumentException.class); }
@Test public void hideError() { Perhaps.error(new IOException()) .hide() .test() .assertFailure(IOException.class); }
@SuppressWarnings("unchecked") @Test public void concatIterableError2() { Perhaps.concat(Arrays.asList(Perhaps.error(new IOException()), Perhaps.just(2))) .test() .assertFailure(IOException.class); }
@Test public void mapErrorThrows() { Perhaps.error(new IOException()) .mapError(new Function<Throwable, Throwable>() { @Override public Throwable apply(Throwable t) throws Exception { throw new IllegalArgumentException(); } }) .test() .assertFailure(CompositeException.class); }
@Test public void onErrorComplete() { Perhaps.error(new IOException()) .onErrorComplete() .test() .assertResult(); }
@SuppressWarnings("unchecked") @Test public void concatArrayDelayErrorError2() { Perhaps.concatArrayDelayError(Perhaps.error(new IOException()), Perhaps.just(2)) .test() .assertFailure(IOException.class, 2); }
@SuppressWarnings("unchecked") @Test public void zipArrayError2() { Perhaps.zipArray(new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }, Perhaps.just(1), Perhaps.error(new IOException())) .test() .assertFailure(IOException.class); }
@Test public void concatDelayErrorPublisherError() { Perhaps.concatDelayError(Flowable.just(Perhaps.just(1), Perhaps.error(new IOException()))) .test() .assertFailure(IOException.class, 1); }
@Test public void concatDelayErrorPublisherError2() { Perhaps.concatDelayError(Flowable.just(Perhaps.error(new IOException()), Perhaps.just(2))) .test() .assertFailure(IOException.class); }
@Test public void mergeDelayErrorPublisherError2() { Perhaps.mergeDelayError(Flowable.just(Perhaps.error(new IOException()), Perhaps.just(2))) .test() .assertFailure(IOException.class, 2); }
@Test public void delayPublisherError2() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = Perhaps.<Integer>error(new IOException()) .delay(pp).test(); ts.assertEmpty(); assertTrue(pp.hasSubscribers()); pp.onError(new IllegalArgumentException()); ts.assertFailure(CompositeException.class); assertFalse(pp.hasSubscribers()); }
@Test public void flatMapSignalError() { Perhaps.error(new IOException()).flatMap( Functions.justFunction(Perhaps.just(2)), Functions.justFunction(Perhaps.just(3)), Functions.justCallable(Perhaps.just(4)) ) .test() .assertResult(3); }
@Test public void flatMapSignalError2() { Perhaps.just(1).flatMap( Functions.justFunction(Perhaps.error(new IOException())), Functions.justFunction(Perhaps.just(3)), Functions.justCallable(Perhaps.just(4)) ) .test() .assertFailure(IOException.class); }