public void groupByKeyNull() { just1.groupBy(new Function<Integer, Object>() { @Override public Object apply(Integer v) { return null; } }).blockingSubscribe(); }
@Test(expected = NullPointerException.class) public void groupByValueNull() { just1.groupBy(new Function<Integer, Object>() { @Override public Object apply(Integer v) { return v; } }, null); }
@Override public Object apply(Flowable<Object> f) throws Exception { return f.groupBy(Functions.justFunction(1)); } }, false, 1, 1, (Object[])null);
@Override public Publisher<GroupedFlowable<Integer, Object>> apply(Flowable<Object> f) throws Exception { return f.groupBy(Functions.justFunction(1)); } });
@Test(expected = NullPointerException.class) public void groupByNull() { just1.groupBy(null); }
@Test public void testGroupByWithElementSelector() { Flowable<String> source = Flowable.just("one", "two", "three", "four", "five", "six"); Flowable<GroupedFlowable<Integer, Integer>> grouped = source.groupBy(length, length); Map<Integer, Collection<Integer>> map = toMap(grouped); assertEquals(3, map.size()); assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray()); assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray()); }
@Test public void testGroupBy() { Flowable<String> source = Flowable.just("one", "two", "three", "four", "five", "six"); Flowable<GroupedFlowable<Integer, String>> grouped = source.groupBy(length); Map<Integer, Collection<String>> map = toMap(grouped); assertEquals(3, map.size()); assertArrayEquals(Arrays.asList("one", "two", "six").toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList("four", "five").toArray(), map.get(4).toArray()); assertArrayEquals(Arrays.asList("three").toArray(), map.get(5).toArray()); }
@Test public void testGroupByWithElementSelector2() { Flowable<String> source = Flowable.just("one", "two", "three", "four", "five", "six"); Flowable<GroupedFlowable<Integer, Integer>> grouped = source.groupBy(length, length); Map<Integer, Collection<Integer>> map = toMap(grouped); assertEquals(3, map.size()); assertArrayEquals(Arrays.asList(3, 3, 3).toArray(), map.get(3).toArray()); assertArrayEquals(Arrays.asList(4, 4).toArray(), map.get(4).toArray()); assertArrayEquals(Arrays.asList(5).toArray(), map.get(5).toArray()); }
@Test public void testEmpty() { Flowable<String> source = Flowable.empty(); Flowable<GroupedFlowable<Integer, String>> grouped = source.groupBy(length); Map<Integer, Collection<String>> map = toMap(grouped); assertTrue(map.isEmpty()); }
@Test public void badRequest() { TestHelper.assertBadRequestReported(Flowable.just(1) .groupBy(Functions.justFunction(1))); }
@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 groupComplete() { Flowable.just(1) .groupBy(Functions.justFunction(1), true) .flatMap(new Function<GroupedFlowable<Integer, Integer>, Publisher<Integer>>() { @Override public Publisher<Integer> apply(GroupedFlowable<Integer, Integer> g) throws Exception { return g.hide(); } }) .test() .assertResult(1); }
@Test public void delayErrorSimpleComplete() { Flowable.just(1) .groupBy(Functions.justFunction(1), true) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .assertResult(1); }
@Test public void errorFusedDelayed() { TestSubscriber<Object> ts = SubscriberFusion.newTest(QueueFuseable.ANY); Flowable.error(new TestException()) .groupBy(Functions.justFunction(1), true) .subscribe(ts); SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) .assertFailure(TestException.class); }
@Test public void errorFused() { TestSubscriber<Object> ts = SubscriberFusion.newTest(QueueFuseable.ANY); Flowable.error(new TestException()) .groupBy(Functions.justFunction(1)) .subscribe(ts); SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) .assertFailure(TestException.class); }
@Test public void mainFusionRejected() { TestSubscriber<Flowable<Integer>> ts = SubscriberFusion.newTest(QueueFuseable.SYNC); Flowable.just(1) .groupBy(Functions.justFunction(1)) .subscribe(ts); SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) .assertValueCount(1) .assertComplete() .assertNoErrors(); }
@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(); }
@Test public void keyAndValueSelectorAndDelayError() { Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException())) .groupBy(Functions.<Integer>identity(), Functions.<Integer>identity(), true) .flatMap(new Function<GroupedFlowable<Integer, Integer>, Flowable<Integer>>() { @Override public Flowable<Integer> apply(GroupedFlowable<Integer, Integer> g) throws Exception { return g; } }) .test() .assertFailure(TestException.class, 1); }
@Test public void testError2() { Flowable<Integer> source = Flowable.concat(Flowable.just(0), Flowable.<Integer> error(new TestException("Forced failure"))); Flowable<Integer> m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); TestSubscriber<Object> ts = new TestSubscriber<Object>(); m.subscribe(ts); ts.awaitTerminalEvent(); assertEquals(1, ts.errorCount()); ts.assertValueCount(1); }