/** * Creates a TestSubscriber with the given initial request and * subscribes it to this Solo. * @param initialRequest the initial request amount, non-negative * @return the new TestSubscriber */ public final TestSubscriber<T> test(long initialRequest) { return test(initialRequest, false); }
@Test public void fromCallableNull() { Solo.fromCallable(new Callable<Object>() { @Override public Object call() throws Exception { return null; } }) .test() .assertFailure(NullPointerException.class); }
@SuppressWarnings("unchecked") @Test public void zipError1() { Solo.zip(Arrays.asList(Solo.error(new IOException()), Solo.just(2)), new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }) .test() .assertFailure(IOException.class); }
@SuppressWarnings("unchecked") @Test public void zip() { Solo.zip(Arrays.asList(Solo.just(1), Solo.just(2)), new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }) .test() .assertResult("12"); }
@SuppressWarnings("unchecked") @Test public void zipArrayError1() { Solo.zipArray(new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }, Solo.error(new IOException()), Solo.just(2)) .test() .assertFailure(IOException.class); }
@SuppressWarnings("unchecked") @Test public void zipArrayError2() { Solo.zipArray(new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }, Solo.just(1), Solo.error(new IOException())) .test() .assertFailure(IOException.class); }
@Test public void delayError() { Solo.error(new IOException()).delay(100, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IOException.class); }
@Test public void andThenNonoError() { Solo.just(1).andThen(Nono.error(new IOException())) .test() .assertFailure(IOException.class); }
@Test public void takeUnitError() { Solo.error(new IOException()).takeUntil(Solo.never()) .test() .assertFailure(IOException.class); }
@Test public void fromPublisherSolo() { Solo.fromPublisher(Solo.just(1)) .test() .assertResult(1); }
@Test public void fromPublisher1() { Solo.fromPublisher(Flowable.just(1)) .test() .assertResult(1); }
@Test public void flatMapError() { Solo.just(1).flatMap(Functions.justFunction(Solo.error(new IOException()))) .test() .assertFailure(IOException.class); }
@Test public void flatMapError2() { Solo.error(new IOException()).flatMap(Functions.justFunction(Solo.just(2))) .test() .assertFailure(IOException.class); }
@Test public void usingEagerError() { Solo.using(Functions.justCallable(1), Functions.justFunction(Solo.error(new IOException())), this) .test() .assertFailure(IOException.class); assertEquals(1, count); }
@SuppressWarnings("unchecked") @Test public void zipArray() { Solo.zipArray(new Function<Object[], Object>() { @Override public Object apply(Object[] a) throws Exception { return "" + a[0] + a[1]; } }, Solo.just(1), Solo.just(2)) .test() .assertResult("12"); }
@Test public void zipWith() { Solo.just(1).zipWith(Solo.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 doAfterTerminate() { Solo.just(1) .doAfterTerminate(this) .test() .assertResult(1); assertEquals(1, count); }
@Test public void usingNonEager() { Solo.using(Functions.justCallable(1), Functions.justFunction(Solo.just(1)), this, false) .test() .assertResult(1); assertEquals(1, count); }
@Test public void delayPublisherError() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = Solo.<Integer>error(new IOException()) .delay(pp).test(); ts.assertEmpty(); assertTrue(pp.hasSubscribers()); pp.onNext(2); ts.assertFailure(IOException.class); assertFalse(pp.hasSubscribers()); }