本文整理了Java中io.reactivex.Observable.fromIterable()
方法的一些代码示例,展示了Observable.fromIterable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.fromIterable()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:fromIterable
[英]Converts an Iterable sequence into an ObservableSource that emits the items in the sequence.
Scheduler: fromIterable does not operate by default on a particular Scheduler.
[中]将Iterable序列转换为ObservableSource,该源发出序列中的项。
调度器:默认情况下,fromIterable不会在特定的调度器上运行。
代码示例来源:origin: ReactiveX/RxJava
/**
* This won't compile if super/extends isn't done correctly on generics.
*/
@Test
public void testCovarianceOfFrom() {
Observable.<Movie> just(new HorrorMovie());
Observable.<Movie> fromIterable(new ArrayList<HorrorMovie>());
// Observable.<HorrorMovie>from(new Movie()); // may not compile
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFlatMapTransformsOnCompletedFuncThrows() {
Observable<Integer> onNext = Observable.fromIterable(Arrays.asList(1, 2, 3));
Observable<Integer> onComplete = Observable.fromIterable(Arrays.asList(4));
Observable<Integer> onError = Observable.fromIterable(Arrays.asList(5));
Observable<Integer> source = Observable.fromIterable(Arrays.<Integer> asList());
Observer<Object> o = TestHelper.mockObserver();
source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(o);
verify(o).onError(any(TestException.class));
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFlatMapTransformsOnNextFuncThrows() {
Observable<Integer> onComplete = Observable.fromIterable(Arrays.asList(4));
Observable<Integer> onError = Observable.fromIterable(Arrays.asList(5));
Observable<Integer> source = Observable.fromIterable(Arrays.asList(10, 20, 30));
Observer<Object> o = TestHelper.mockObserver();
source.flatMap(funcThrow(1, onError), just(onError), just0(onComplete)).subscribe(o);
verify(o).onError(any(TestException.class));
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testList() {
Observable<String> w = Observable.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));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testListViaObservable() {
Observable<String> w = Observable.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));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testListIterable() {
Observable<String> o = Observable.fromIterable(Arrays.<String> asList("one", "two", "three"));
Observer<String> observer = TestHelper.mockObserver();
o.subscribe(observer);
verify(observer, times(1)).onNext("one");
verify(observer, times(1)).onNext("two");
verify(observer, times(1)).onNext("three");
verify(observer, Mockito.never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipLast2() {
Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two")).skipLast(2);
Observer<String> observer = TestHelper.mockObserver();
o.subscribe(observer);
verify(observer, never()).onNext(any(String.class));
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTake1() {
Observable<String> w = Observable.fromIterable(Arrays.asList("one", "two", "three"));
Observable<String> take = w.take(2);
Observer<String> observer = TestHelper.mockObserver();
take.subscribe(observer);
verify(observer, times(1)).onNext("one");
verify(observer, times(1)).onNext("two");
verify(observer, never()).onNext("three");
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTake2() {
Observable<String> w = Observable.fromIterable(Arrays.asList("one", "two", "three"));
Observable<String> take = w.take(1);
Observer<String> observer = TestHelper.mockObserver();
take.subscribe(observer);
verify(observer, times(1)).onNext("one");
verify(observer, never()).onNext("two");
verify(observer, never()).onNext("three");
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Null values are not allowed")
public void testListWithNullValue() {
Observable<String> w = Observable.fromIterable(Arrays.asList("one", null, "three"));
Single<List<String>> single = w.toList();
SingleObserver<List<String>> observer = TestHelper.mockSingleObserver();
single.subscribe(observer);
verify(observer, times(1)).onSuccess(Arrays.asList("one", null, "three"));
verify(observer, Mockito.never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void fromIterableIteratorNull() {
Observable.fromIterable(new Iterable<Object>() {
@Override
public Iterator<Object> iterator() {
return null;
}
}).blockingLast();
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = IllegalArgumentException.class)
public void testTakeWithError() {
Observable.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();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Null values not allowed")
public void testSkipLastWithNull() {
Observable<String> o = Observable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1);
Observer<String> observer = TestHelper.mockObserver();
o.subscribe(observer);
verify(observer, times(1)).onNext("one");
verify(observer, times(1)).onNext(null);
verify(observer, never()).onNext("two");
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Null values are not allowed")
public void testListWithNullValueObservable() {
Observable<String> w = Observable.fromIterable(Arrays.asList("one", null, "three"));
Observable<List<String>> observable = w.toList().toObservable();
Observer<List<String>> observer = TestHelper.mockObserver();
observable.subscribe(observer);
verify(observer, times(1)).onNext(Arrays.asList("one", null, "three"));
verify(observer, Mockito.never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testListWithBlockingFirst() {
Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two", "three"));
List<String> actual = o.toList().blockingGet();
Assert.assertEquals(Arrays.asList("one", "two", "three"), actual);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSwitchWhenEmpty() throws Exception {
final Observable<Integer> o = Observable.<Integer>empty()
.switchIfEmpty(Observable.fromIterable(Arrays.asList(42)));
assertEquals(42, o.blockingSingle().intValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSubscribeMultipleTimes() {
Observable<Integer> o = Observable.fromIterable(Arrays.asList(1, 2, 3));
for (int i = 0; i < 10; i++) {
TestObserver<Integer> to = new TestObserver<Integer>();
o.subscribe(to);
to.assertValues(1, 2, 3);
to.assertNoErrors();
to.assertComplete();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void hasNext2Throws() {
Observable.fromIterable(new CrashingIterable(100, 2, 100))
.test()
.assertFailureAndMessage(TestException.class, "hasNext()", 0);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void iteratorThrows() {
Observable.fromIterable(new CrashingIterable(1, 100, 100))
.test()
.assertFailureAndMessage(TestException.class, "iterator()");
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void syncIterableHidden() {
Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
.hide()
.to(ObserverFusion.<Integer>test(QueueFuseable.ANY, false))
.assertOf(ObserverFusion.<Integer>assertNotFuseable())
.assertOf(ObserverFusion.<Integer>assertFusionMode(QueueFuseable.NONE))
.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
.assertNoErrors()
.assertComplete();
}
}
内容来源于网络,如有侵权,请联系作者删除!