@Override public MaybeSource<Integer> apply(Flowable<Integer> f) throws Exception { return f.reduce(sum); } });
public void libraryFunctionActingOnMovieObservables(Flowable<Movie> obs) { obs.reduce(new BiFunction<Movie, Movie, Movie>() { @Override public Movie apply(Movie t1, Movie t2) { return t2; } }); }
@Override public Object apply(Flowable<Integer> f) throws Exception { return f.reduce(sum); } }, false, 1, 1, 1);
@Override public SingleSource<Integer> apply(Flowable<Integer> f) throws Exception { return f.reduce(0, new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) throws Exception { return a; } }); } });
@Override public Object apply(Flowable<Integer> f) throws Exception { return f.reduce(sum).toFlowable(); } }, false, 1, 1, 1);
@Test(expected = NullPointerException.class) public void reduceSeedNull() { just1.reduce(null, new BiFunction<Object, Integer, Object>() { @Override public Object apply(Object a, Integer b) { return 1; } }); }
@Test(expected = NullPointerException.class) public void reduceSeedFunctionReturnsNull() { just1.reduce(1, new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) { return null; } }).blockingGet(); }
@Override public Publisher<Integer> createPublisher(final long elements) { return Flowable.range(1, 1000).reduce(new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) throws Exception { return a + b; } }).toFlowable() ; }
@Test public void testBackpressureWithNoInitialValue() throws InterruptedException { Flowable<Integer> source = Flowable.just(1, 2, 3, 4, 5, 6); Maybe<Integer> reduced = source.reduce(sum); Integer r = reduced.blockingGet(); assertEquals(21, r.intValue()); }
@Test public void testBackpressureWithNoInitialValueObservable() throws InterruptedException { Flowable<Integer> source = Flowable.just(1, 2, 3, 4, 5, 6); Flowable<Integer> reduced = source.reduce(sum).toFlowable(); Integer r = reduced.blockingFirst(); assertEquals(21, r.intValue()); }
@Test public void testBackpressureWithInitialValueFlowable() throws InterruptedException { Flowable<Integer> source = Flowable.just(1, 2, 3, 4, 5, 6); Flowable<Integer> reduced = source.reduce(0, sum).toFlowable(); Integer r = reduced.blockingFirst(); assertEquals(21, r.intValue()); }
@Test(expected = NullPointerException.class) public void reduceFunctionReturnsNull() { Flowable.just(1, 1).reduce(new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) { return null; } }).toFlowable().blockingSubscribe(); }
@Test public void empty() { Flowable.<Integer>empty() .reduce(sum) .test() .assertResult(); }
@Test public void reducerThrows() { Flowable.just(1, 2) .reduce(new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer a, Integer b) throws Exception { throw new TestException(); } }) .test() .assertFailure(TestException.class); }
@Test public void source() { Flowable<Integer> source = Flowable.just(1); assertSame(source, (((HasUpstreamPublisher<?>)source.reduce(sum))).source()); }
@Test public void reduceIntsFlowable() { Flowable<Integer> f = Flowable.just(1, 2, 3); int value = f.reduce(new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }).toFlowable().blockingSingle(); assertEquals(6, value); }
@Test public void reduceInts() { Flowable<Integer> f = Flowable.just(1, 2, 3); int value = f.reduce(new BiFunction<Integer, Integer, Integer>() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; } }).toFlowable().blockingSingle(); assertEquals(6, value); }
@Test public void error() { Flowable.<Integer>error(new TestException()) .reduce(sum) .test() .assertFailure(TestException.class); }
@Test public void emptyFlowable() { Flowable.<Integer>empty() .reduce(sum) .toFlowable() .test() .assertResult(); }
@Test public void errorFlowable() { Flowable.<Integer>error(new TestException()) .reduce(sum) .toFlowable() .test() .assertFailure(TestException.class); }