@Override public MaybeSource<Integer> apply(Maybe<Integer> v) throws Exception { return v.flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.just(2); } }); } });
@Test public void dispose() { TestHelper.checkDisposed(Maybe.just(1).flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.just(2); } })); }
@Test public void mainEmpty() { Maybe.<Integer>empty() .flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.just(2); } }) .test() .assertResult(); }
@Test public void flatMap() { Maybe.just(1).flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.just(v * 10); } }) .test() .assertResult(10); }
@Test public void flatMapEmpty() { Maybe.just(1).flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.empty(); } }) .test() .assertResult(); }
@Test public void flatMapError() { Maybe.just(1).flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.error(new TestException()); } }) .test() .assertFailure(TestException.class); }
@Test public void mapperReturnsNull() { Maybe.just(1) .flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return null; } }) .test() .assertFailure(NullPointerException.class); } }
@Test public void mapperThrows() { Maybe.just(1) .flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { throw new TestException(); } }) .test() .assertFailure(TestException.class); }
@Test public void mapperReturnsNull() { Maybe.just(1) .flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return null; } }, stringCombine()) .test() .assertFailure(NullPointerException.class); }
@Test public void mainError() { Maybe.<Integer>error(new TestException()) .flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.just(2); } }) .test() .assertFailure(TestException.class); }
@Test public void normal() { Maybe.just(1) .flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.just(2); } }, stringCombine()) .test() .assertResult("1:2"); }
@Test public void normalWithEmpty() { Maybe.just(1) .flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { return Maybe.empty(); } }, stringCombine()) .test() .assertResult(); }
@Test public void mapperThrows() { Maybe.just(1) .flatMap(new Function<Integer, MaybeSource<Integer>>() { @Override public MaybeSource<Integer> apply(Integer v) throws Exception { throw new TestException(); } }, stringCombine()) .test() .assertFailure(TestException.class); }
@Override public MaybeSource<Integer> apply(Maybe<Integer> m) throws Exception { return m .flatMap(Functions.justFunction(Maybe.just(1)), Functions.justFunction(Maybe.just(1)), Functions.justCallable(Maybe.just(1))); } });
@Test public void onSuccessNull() { Maybe.just(1) .flatMap(Functions.justFunction((Maybe<Integer>)null), Functions.justFunction(Maybe.just(1)), Functions.justCallable(Maybe.just(1))) .test() .assertFailure(NullPointerException.class); }
@Test public void dispose() { TestHelper.checkDisposed(Maybe.just(1) .flatMap(Functions.justFunction(Maybe.just(1)), Functions.justFunction(Maybe.just(1)), Functions.justCallable(Maybe.just(1)))); }
@Test public void onCompleteNull() { Maybe.<Integer>empty() .flatMap(Functions.justFunction(Maybe.just(1)), Functions.justFunction(Maybe.just(1)), Functions.justCallable((Maybe<Integer>)null)) .test() .assertFailure(NullPointerException.class); }
@Test public void onErrorNull() { TestObserver<Integer> to = Maybe.<Integer>error(new TestException()) .flatMap(Functions.justFunction(Maybe.just(1)), Functions.justFunction((Maybe<Integer>)null), Functions.justCallable(Maybe.just(1))) .test() .assertFailure(CompositeException.class); List<Throwable> ce = TestHelper.compositeList(to.errors().get(0)); TestHelper.assertError(ce, 0, TestException.class); TestHelper.assertError(ce, 1, NullPointerException.class); }
@Test public void onSuccessError() { Maybe.just(1) .flatMap(Functions.justFunction(Maybe.<Integer>error(new TestException())), Functions.justFunction((Maybe<Integer>)null), Functions.justCallable(Maybe.just(1))) .test() .assertFailure(TestException.class); } }
@Test public void onSuccessEmpty() { Maybe.just(1) .flatMap(Functions.justFunction(Maybe.<Integer>empty()), Functions.justFunction(Maybe.just(1)), Functions.justCallable(Maybe.just(1))) .test() .assertResult(); }