@Override public Object apply(Flowable<Object> f) throws Exception { return f.window(Flowable.never()).flatMap(new Function<Flowable<Object>, Flowable<Object>>() { @Override public Flowable<Object> apply(Flowable<Object> v) throws Exception { return v; } }); } }, false, 1, 1, 1);
@Test(expected = NullPointerException.class) public void flatMapFunctionReturnsNull() { just1.flatMap(new Function<Integer, Publisher<Object>>() { @Override public Publisher<Object> apply(Integer v) { return null; } }).blockingSubscribe(); }
@Override public Publisher<Movie> apply(Flowable<List<Movie>> movieList) { return movieList .startWith(new ArrayList<Movie>()) .buffer(2, 1) .skip(1) .flatMap(calculateDelta); } };
@Test public void testFlatMapTransformsOnCompletedFuncThrows() { Flowable<Integer> onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); Flowable<Integer> onComplete = Flowable.fromIterable(Arrays.asList(4)); Flowable<Integer> onError = Flowable.fromIterable(Arrays.asList(5)); Flowable<Integer> source = Flowable.fromIterable(Arrays.<Integer> asList()); Subscriber<Object> subscriber = TestHelper.mockSubscriber(); source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(subscriber); verify(subscriber).onError(any(TestException.class)); verify(subscriber, never()).onNext(any()); verify(subscriber, never()).onComplete(); }
@Test public void testFlatMapTransformsMergeException() { Flowable<Integer> onNext = Flowable.error(new TestException()); Flowable<Integer> onComplete = Flowable.fromIterable(Arrays.asList(4)); Flowable<Integer> onError = Flowable.fromIterable(Arrays.asList(5)); Flowable<Integer> source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); Subscriber<Object> subscriber = TestHelper.mockSubscriber(); source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(subscriber); verify(subscriber).onError(any(TestException.class)); verify(subscriber, never()).onNext(any()); verify(subscriber, never()).onComplete(); }
@Test public void flatMapEmpty() { assertSame(Flowable.empty(), Flowable.empty().flatMap(new Function<Object, Publisher<Object>>() { @Override public Publisher<Object> apply(Object v) throws Exception { return Flowable.just(v); } })); }
@Test public void timespanTimeskipCustomSchedulerBufferSize() { Flowable.range(1, 10) .window(1, 1, TimeUnit.MINUTES, Schedulers.io(), 2) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); }
@Test public void innerEscapeCompleted() { Flowable<Integer> source = Flowable.just(0); Flowable<Integer> m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); TestSubscriber<Object> ts = new TestSubscriber<Object>(); m.subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); System.out.println(ts.values()); }
@Test public void delayErrorSimpleComplete() { Flowable.just(1) .groupBy(Functions.justFunction(1), true) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .assertResult(1); }
@Test public void timespanTimeskipDefaultScheduler() { Flowable.just(1) .window(1, 1, TimeUnit.MINUTES) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void restartTimer() { Flowable.range(1, 5) .window(1, TimeUnit.DAYS, Schedulers.single(), 2, true) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .assertResult(1, 2, 3, 4, 5); }
@Test public void timespanDefaultSchedulerSize() { Flowable.range(1, 10) .window(1, TimeUnit.MINUTES, 20) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); }
@Test public void timespanDefaultSchedulerSizeRestart() { Flowable.range(1, 10) .window(1, TimeUnit.MINUTES, 20, true) .flatMap(Functions.<Flowable<Integer>>identity(), true) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); }
@Test public void boundaryOnError() { TestSubscriber<Object> ts = Flowable.error(new TestException()) .window(Flowable.never()) .flatMap(Functions.<Flowable<Object>>identity(), true) .test() .assertFailure(CompositeException.class); List<Throwable> errors = TestHelper.compositeList(ts.errors().get(0)); TestHelper.assertError(errors, 0, TestException.class); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Publisher<List<Long>> createPublisher(long elements) { return Flowable.fromIterable(iterate(elements)) .window(Flowable.just(1).concatWith(Flowable.<Integer>never())) .onBackpressureBuffer() .flatMap((Function)Functions.identity()) ; } }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void flatMapJustRange() { TestSubscriber<Integer> ts = TestSubscriber.create(); Flowable.just(Flowable.range(1, 5)).flatMap((Function)Functions.identity()).subscribe(ts); ts.assertValues(1, 2, 3, 4, 5); ts.assertNoErrors(); ts.assertComplete(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void flatMapMaxConcurrentJustJust() { TestSubscriber<Integer> ts = TestSubscriber.create(); Flowable.just(Flowable.just(1)).flatMap((Function)Functions.identity(), 5).subscribe(ts); ts.assertValue(1); ts.assertNoErrors(); ts.assertComplete(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void flatMapJustJust() { TestSubscriber<Integer> ts = TestSubscriber.create(); Flowable.just(Flowable.just(1)).flatMap((Function)Functions.identity()).subscribe(ts); ts.assertValue(1); ts.assertNoErrors(); ts.assertComplete(); }
@Test public void keySelectorThrows() { Flowable<Integer> source = Flowable.just(0, 1, 2, 3, 4, 5, 6); Flowable<Integer> m = source.groupBy(fail(0), dbl).flatMap(FLATTEN_INTEGER); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); m.subscribe(ts); ts.awaitTerminalEvent(); assertEquals(1, ts.errorCount()); ts.assertNoValues(); }
@Test public void valueSelectorThrows() { Flowable<Integer> source = Flowable.just(0, 1, 2, 3, 4, 5, 6); Flowable<Integer> m = source.groupBy(identity, fail(0)).flatMap(FLATTEN_INTEGER); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); m.subscribe(ts); ts.awaitTerminalEvent(); assertEquals(1, ts.errorCount()); ts.assertNoValues(); }