@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); }
@Test public void fromPublisherError() { Perhaps.fromPublisher(Flowable.error(new IOException())) .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 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 doFinallyError() { Perhaps.error(new IOException()) .doFinally(this) .test() .assertFailure(IOException.class); assertEquals(1, count); }
@Test public void fromCallable() { Perhaps.fromCallable(Functions.justCallable(1)) .test() .assertResult(1); }
@Test public void map() { Perhaps.just(1).map(new Function<Integer, Object>() { @Override public Object apply(Integer v) throws Exception { return v + 1; } }) .test() .assertResult(2); }
@Test public void mapNull() { Perhaps.just(1).map(new Function<Integer, Object>() { @Override public Object apply(Integer v) throws Exception { return null; } }) .test() .assertFailure(NullPointerException.class); }
@Test public void zipWith() { Perhaps.just(1).zipWith(Perhaps.just(2), new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) throws Exception { return a + b; } }) .test() .assertResult(3); }
@Test public void delay() { Perhaps.just(1).delay(100, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void doOnRequest() { Perhaps.just(1) .doOnRequest(this) .test() .assertResult(1); assertEquals(1, count); }
@Test public void doFinally() { Perhaps.just(1) .doFinally(this) .test() .assertResult(1); assertEquals(1, count); }
@Test public void switchIfEmpty() { Perhaps.empty() .switchIfEmpty(Perhaps.just(2)) .test() .assertResult(2); }
@Test public void usingEager() { Perhaps.using(Functions.justCallable(1), Functions.justFunction(Perhaps.just(1)), this) .test() .assertResult(1); assertEquals(1, count); }
@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); }
@Test public void timeoutPublisher() { PerhapsProcessor<Integer> sp = PerhapsProcessor.create(); sp.timeout(Flowable.empty()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); assertFalse(sp.hasSubscribers()); }
@Test public void flatMapSignal() { Perhaps.just(1).flatMap( Functions.justFunction(Perhaps.just(2)), Functions.justFunction(Perhaps.just(3)), Functions.justCallable(Perhaps.just(4)) ) .test() .assertResult(2); }
@Test public void doOnCancel() { PerhapsProcessor<Integer> sp = PerhapsProcessor.create(); TestSubscriber<Integer> ts = sp.doOnCancel(this) .test() .assertEmpty(); assertEquals(0, count); assertTrue(sp.hasSubscribers()); ts.cancel(); assertFalse(sp.hasSubscribers()); assertEquals(1, count); }