@Override public Flowable<Integer> apply(Flowable<Integer> f) { return f.take(1); } }).subscribe(ts);
@Test public void fromArray() { String[] items = new String[] { "one", "two", "three" }; assertEquals((Long)3L, Flowable.fromArray(items).count().blockingGet()); assertEquals("two", Flowable.fromArray(items).skip(1).take(1).blockingSingle()); assertEquals("three", Flowable.fromArray(items).takeLast(1).blockingSingle()); }
@Override public Flowable<Integer> apply(Flowable<Integer> f) { return f.take(1); } }).subscribe(ts);
@Override public Flowable<Object> apply(Flowable<Object> handler) throws Exception { return handler.take(2); } })
@Override public Flowable<Integer> apply( Flowable<Integer> w) throws Exception { return w.take(1); } })
@Test(timeout = 2000) public void testUnsubscribeFromSynchronousInfiniteFlowable() { final AtomicLong count = new AtomicLong(); INFINITE_OBSERVABLE.take(10).subscribe(new Consumer<Long>() { @Override public void accept(Long l) { count.set(l); } }); assertEquals(10, count.get()); }
@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 public void testTakeFirstWithPredicateOfSome() { Flowable<Integer> flowable = Flowable.just(1, 3, 5, 4, 6, 3); flowable.filter(IS_EVEN).take(1).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(4); verify(w, times(1)).onComplete(); verify(w, never()).onError(any(Throwable.class)); }
@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(); }
@Test public void take() { Flowable.range(1, 3) .flatMapIterable(Functions.justFunction(Arrays.asList(1)), 1) .take(1) .test() .assertResult(1); }
@Test public void take() { Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS) .take(1) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1L); }
@Test public void take() { Maybe.just(1).flattenAsFlowable(new Function<Integer, Iterable<Integer>>() { @Override public Iterable<Integer> apply(Integer v) throws Exception { return Arrays.asList(v, v + 1); } }) .take(1) .test() .assertResult(1); }
@Test public void take() { Flowable.range(1, 5) .mergeWith(Single.just(100)) .take(3) .test() .assertResult(1, 2, 3); }
@Test public void conditionalSlowPathTakeExact() { Flowable.range(1, 5) .filter(Functions.alwaysTrue()) .take(5) .test() .assertResult(1, 2, 3, 4, 5); }
@Test public void take() { Flowable.range(1, 5) .mergeWith(Maybe.just(100)) .take(3) .test() .assertResult(1, 2, 3); }
@Test public void slowPathTakeExact() { Flowable.rangeLong(1L, 5L) .filter(Functions.alwaysTrue()) .take(5) .test() .assertResult(1L, 2L, 3L, 4L, 5L); }
@Test public void takeOne() { Flowable.create(source, BackpressureStrategy.BUFFER).take(1).subscribe(ts); ts.request(2); source.onNext(1); source.onNext(2); source.onComplete(); ts.assertValues(1); ts.assertNoErrors(); ts.assertComplete(); }
@Test public void takeHalf() { int elements = 1024; Flowable.range(0, elements * 2).unsubscribeOn(Schedulers.single()) .take(elements) .test() .awaitDone(5, TimeUnit.SECONDS) .assertValueCount(elements) .assertComplete() .assertNoErrors() .assertSubscribed(); }
@Test public void normalConditionalLong() { Flowable.fromIterable(new CrashingIterable(100, 10 * 1000 * 1000, 10 * 1000 * 1000)) .filter(Functions.alwaysTrue()) .take(1000 * 1000) .test() .assertSubscribed() .assertValueCount(1000 * 1000) .assertNoErrors() .assertComplete(); }
@Test public void selectorFallbackTake() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = pp .timeout(Functions.justFunction(Flowable.never()), Flowable.just(2)) .take(1) .test(); assertTrue(pp.hasSubscribers()); pp.onNext(1); assertFalse(pp.hasSubscribers()); ts.assertResult(1); }