@Override public Flowable<Integer> apply(Integer t) { return Flowable.fromIterable(Arrays.asList(t)); } })
@Override public Flowable<Long> apply(Long t) { return Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)).hide(); } }).take(3)).subscribe(ts);
@Override public Publisher<Long> createPublisher(long elements) { return Flowable.fromIterable(iterate(elements)); } }
@Override public Publisher<Long> createPublisher(long elements) { return Flowable.merge( Flowable.fromIterable(iterate(elements / 2)), Flowable.fromIterable(iterate(elements - elements / 2)) ) ; } }
@Test public void testListViaFlowable() { Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); Single<List<String>> single = w.toList(); SingleObserver<List<String>> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); verify(observer, times(1)).onSuccess(Arrays.asList("one", "two", "three")); verify(observer, Mockito.never()).onError(any(Throwable.class)); }
@Override public Publisher<Long> createPublisher(long elements) { return Flowable.concat(Flowable.just( Flowable.fromIterable(iterate(elements / 2)), Flowable.fromIterable(iterate(elements - elements / 2)) ) ) ; } }
@Override public Publisher<Long> createPublisher(long elements) { return Flowable.merge(Flowable.just( Flowable.fromIterable(iterate(elements / 2)), Flowable.fromIterable(iterate(elements - elements / 2)) ) ) ; } }
@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 testTake1() { Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); Flowable<String> take = w.take(2); Subscriber<String> subscriber = TestHelper.mockSubscriber(); take.subscribe(subscriber); verify(subscriber, times(1)).onNext("one"); verify(subscriber, times(1)).onNext("two"); verify(subscriber, never()).onNext("three"); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test @Ignore("Null values not allowed") public void testSkipLastWithNull() { Flowable<String> flowable = Flowable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); Subscriber<String> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); verify(subscriber, times(1)).onNext("one"); verify(subscriber, times(1)).onNext(null); verify(subscriber, never()).onNext("two"); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test public void testWrappingMock() { Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2)); Subscriber<Integer> mockSubscriber = TestHelper.mockSubscriber(); oi.subscribe(new TestSubscriber<Integer>(mockSubscriber)); InOrder inOrder = inOrder(mockSubscriber); inOrder.verify(mockSubscriber, times(1)).onNext(1); inOrder.verify(mockSubscriber, times(1)).onNext(2); inOrder.verify(mockSubscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Test public void testWrappingMockWhenUnsubscribeInvolved() { Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2); Subscriber<Integer> mockSubscriber = TestHelper.mockSubscriber(); oi.subscribe(new TestSubscriber<Integer>(mockSubscriber)); InOrder inOrder = inOrder(mockSubscriber); inOrder.verify(mockSubscriber, times(1)).onNext(1); inOrder.verify(mockSubscriber, times(1)).onNext(2); inOrder.verify(mockSubscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Override public Publisher<Long> createPublisher(long elements) { return Flowable.switchOnNext(Flowable.just( Flowable.fromIterable(iterate(elements))) ) ; } }
@Test(expected = IllegalArgumentException.class) public void testTakeWithError() { Flowable.fromIterable(Arrays.asList(1, 2, 3)).take(1) .map(new Function<Integer, Integer>() { @Override public Integer apply(Integer t1) { throw new IllegalArgumentException("some error"); } }).blockingSingle(); }
@Test public void fusionRejected() { TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ASYNC); Flowable.fromIterable(Arrays.asList(1, 2, 3)) .subscribe(ts); SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) .assertResult(1, 2, 3); }
@Test public void testAssert() { Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); oi.subscribe(ts); ts.assertValues(1, 2); ts.assertValueCount(2); ts.assertTerminated(); }
@Test public void testAssertNotMatchValue() { Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); oi.subscribe(ts); thrown.expect(AssertionError.class); // FIXME different message pattern // thrown.expectMessage("Value at index: 1 expected to be [3] (Integer) but was: [2] (Integer)"); ts.assertValues(1, 3); ts.assertValueCount(2); ts.assertTerminated(); }
@Test public void assertNeverAtMatchingValue() { Flowable<Integer> oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); oi.subscribe(ts); ts.assertValues(1, 2); thrown.expect(AssertionError.class); ts.assertNever(2); ts.assertValueCount(2); ts.assertTerminated(); }
@Test public void normalConditionalCrash2() { Flowable.fromIterable(new CrashingIterable(100, 100, 2)) .filter(Functions.alwaysTrue()) .test() .assertFailure(TestException.class, 0); }
@Test public void syncIterableHidden() { Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .hide() .to(SubscriberFusion.<Integer>test(Long.MAX_VALUE, QueueFuseable.ANY, false)) .assertOf(SubscriberFusion.<Integer>assertNotFuseable()) .assertOf(SubscriberFusion.<Integer>assertFusionMode(QueueFuseable.NONE)) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); } }