/** * Collects all remaining objects of this Iterable into a list. * * @return a list with all remaining objects of this Iterable */ @Override public List<E> asList() { return toList(iterable.iterator()); }
@Override public void subscribeActual(Subscriber<? super T> s) { Iterator<? extends T> it; try { it = source.iterator(); } catch (Throwable e) { Exceptions.throwIfFatal(e); EmptySubscription.error(e, s); return; } subscribe(s, it); }
@Override public Integer apply(Integer v) throws Exception { Observable.just(1).delay(10, TimeUnit.SECONDS).blockingIterable().iterator().next(); return v; } })
@Override public Integer apply(Integer v) throws Exception { Observable.just(1).delay(10, TimeUnit.SECONDS).blockingLatest().iterator().hasNext(); return v; } })
@Test public void interrupted() { Iterator<Object> it = Flowable.never().blockingLatest().iterator(); Thread.currentThread().interrupt(); try { it.hasNext(); } catch (RuntimeException ex) { assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); } Thread.interrupted(); }
@Test public void interrupted() { Iterator<Object> it = Observable.never().blockingLatest().iterator(); Thread.currentThread().interrupt(); try { it.hasNext(); } catch (RuntimeException ex) { assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); } Thread.interrupted(); }
@Test(expected = UnsupportedOperationException.class) public void toFlowableIterableRemove() { @SuppressWarnings("unchecked") Iterable<? extends Flowable<Integer>> f = SingleInternalHelper.iterableToFlowable(Arrays.asList(Single.just(1))); Iterator<? extends Flowable<Integer>> iterator = f.iterator(); iterator.next(); iterator.remove(); }
@Test public void interrupt() { Iterator<Object> it = Flowable.never().blockingNext().iterator(); try { Thread.currentThread().interrupt(); it.next(); } catch (RuntimeException ex) { assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); } }
@Override public Integer apply(Integer v) throws Exception { Flowable.just(1).delay(10, TimeUnit.SECONDS).blockingNext().iterator().hasNext(); return v; } })
@Override public Integer apply(Integer v) throws Exception { Flowable.just(1).delay(10, TimeUnit.SECONDS).blockingIterable().iterator().next(); return v; } })
@Test(timeout = 1000, expected = NoSuchElementException.class) public void testEmpty() { Observable<Long> source = Observable.<Long> empty(); Iterable<Long> iter = source.blockingLatest(); Iterator<Long> it = iter.iterator(); Assert.assertEquals(false, it.hasNext()); it.next(); }
@Test(timeout = 1000, expected = RuntimeException.class) public void testNextThrows() { TestScheduler scheduler = new TestScheduler(); Observable<Long> source = Observable.<Long> error(new RuntimeException("Forced failure!")).subscribeOn(scheduler); Iterable<Long> iter = source.blockingLatest(); Iterator<Long> it = iter.iterator(); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); it.next(); }
@Test(/* timeout = 1000, */expected = RuntimeException.class) public void testHasNextThrows() { TestScheduler scheduler = new TestScheduler(); Observable<Long> source = Observable.<Long> error(new RuntimeException("Forced failure!")).subscribeOn(scheduler); Iterable<Long> iter = source.blockingLatest(); Iterator<Long> it = iter.iterator(); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); it.hasNext(); }
@Test public void testSynchronousNext() { assertEquals(1, BehaviorProcessor.createDefault(1).take(1).blockingSingle().intValue()); assertEquals(2, BehaviorProcessor.createDefault(2).blockingIterable().iterator().next().intValue()); assertEquals(3, BehaviorProcessor.createDefault(3).blockingNext().iterator().next().intValue()); }
@Test public void testToIterator() { Flowable<String> obs = Flowable.just("one", "two", "three"); Iterator<String> it = obs.blockingIterable().iterator(); assertEquals(true, it.hasNext()); assertEquals("one", it.next()); assertEquals(true, it.hasNext()); assertEquals("two", it.next()); assertEquals(true, it.hasNext()); assertEquals("three", it.next()); assertEquals(false, it.hasNext()); }
@Test(expected = TestException.class) public void testMostRecentWithException() { FlowableProcessor<String> s = PublishProcessor.create(); Iterator<String> it = s.blockingMostRecent("default").iterator(); assertTrue(it.hasNext()); assertEquals("default", it.next()); assertEquals("default", it.next()); s.onError(new TestException()); assertTrue(it.hasNext()); it.next(); }
@Test(expected = TestException.class) public void testMostRecentWithException() { Subject<String> s = PublishSubject.create(); Iterator<String> it = mostRecent(s, "default").iterator(); assertTrue(it.hasNext()); assertEquals("default", it.next()); assertEquals("default", it.next()); s.onError(new TestException()); assertTrue(it.hasNext()); it.next(); }
@Test(timeout = 1000, expected = RuntimeException.class) public void testNextThrows() { TestScheduler scheduler = new TestScheduler(); Flowable<Long> source = Flowable.<Long> error(new RuntimeException("Forced failure!")).subscribeOn(scheduler); Iterable<Long> iter = source.blockingLatest(); Iterator<Long> it = iter.iterator(); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); it.next(); }
@Test public void error2() { Iterator<Object> it = Observable.error(new TestException()).blockingLatest().iterator(); for (int i = 0; i < 3; i++) { try { it.hasNext(); fail("Should have thrown"); } catch (TestException ex) { // expected } } }
@Test public void error2() { Iterator<Object> it = Flowable.error(new TestException()).blockingLatest().iterator(); for (int i = 0; i < 3; i++) { try { it.hasNext(); fail("Should have thrown"); } catch (TestException ex) { // expected } } }