io.reactivex.Observable.empty()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中io.reactivex.Observable.empty()方法的一些代码示例,展示了Observable.empty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.empty()方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:empty

Observable.empty介绍

[英]Returns an Observable that emits no items to the Observer and immediately invokes its Observer#onComplete method.

Scheduler: empty does not operate by default on a particular Scheduler.
[中]返回一个不向观察者发送任何项的可观察对象,并立即调用其观察者#onComplete方法。
Scheduler:默认情况下,empty不会在特定计划程序上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

@Override
  public Observable<String> call() {
    return Observable.empty();
  }
};

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testSkipEmpty() {
  Observable<Integer> src = Observable.empty();
  src.skipWhile(LESS_THAN_FIVE).subscribe(w);
  verify(w, never()).onNext(anyInt());
  verify(w, never()).onError(any(Throwable.class));
  verify(w, times(1)).onComplete();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testFirstOrElseOfNone() {
  Observable<String> src = Observable.empty();
  src.first("default").subscribe(wo);
  verify(wo, times(1)).onSuccess(anyString());
  verify(wo, times(1)).onSuccess("default");
  verify(wo, never()).onError(any(Throwable.class));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testTakeLastEmpty() {
  Observable<String> w = Observable.empty();
  Observable<String> take = w.takeLast(2);
  Observer<String> observer = TestHelper.mockObserver();
  take.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 testSkipEmptyStream() {
  Observable<String> w = Observable.empty();
  Observable<String> skip = w.skip(1);
  Observer<String> observer = TestHelper.mockObserver();
  skip.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 testFirstWithEmpty() {
  Maybe<Integer> o = Observable.<Integer> empty().firstElement();
  o.subscribe(wm);
  InOrder inOrder = inOrder(wm);
  inOrder.verify(wm, times(1)).onComplete();
  inOrder.verify(wm, never()).onError(any(Throwable.class));
  inOrder.verifyNoMoreInteractions();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testLastWithEmpty() {
  Maybe<Integer> o = Observable.<Integer> empty().lastElement();
  MaybeObserver<Integer> observer = TestHelper.mockMaybeObserver();
  o.subscribe(observer);
  InOrder inOrder = inOrder(observer);
  inOrder.verify(observer).onComplete();
  inOrder.verify(observer, never()).onError(any(Throwable.class));
  inOrder.verifyNoMoreInteractions();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void empty() {
  ConnectableObservable<Integer> co = Observable.<Integer>empty().publish();
  co.connect();
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void bufferTimedExactEmpty() {
  Observable.empty()
  .buffer(1, TimeUnit.DAYS)
  .test()
  .assertResult(Collections.emptyList());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void timedEmptyOther() {
  Observable.empty()
  .timeout(1, TimeUnit.DAYS, Observable.just(1))
  .test()
  .assertResult();
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void assertValuePredicateEmpty() {
  TestObserver<Object> to = new TestObserver<Object>();
  Observable.empty().subscribe(to);
  thrown.expect(AssertionError.class);
  thrown.expectMessage("No values");
  to.assertValue(new Predicate<Object>() {
    @Override public boolean test(final Object o) throws Exception {
      return false;
    }
  });
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void empty() {
  Observable.<Integer>empty()
  .doAfterNext(afterNext)
  .subscribeWith(to)
  .assertResult();
  assertTrue(values.isEmpty());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void elementAtIndex0WithDefaultOnEmptySource() {
  Observable.empty()
    .elementAt(0, 5)
    .test()
    .assertResult(5);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void elementAtOrErrorIndex1OnEmptySource() {
  Observable.empty()
    .elementAtOrError(1)
    .test()
    .assertFailure(NoSuchElementException.class);
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void combineLatestDelayErrorEmpty() {
  assertSame(Observable.empty(), Observable.combineLatestDelayError(new ObservableSource[0], Functions.<Object[]>identity(), 16));
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void testLastWithNoElements() {
  Maybe<?> last = Observable.empty().lastElement();
  assertNull(last.blockingGet());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
  public void testLastOfEmptyReturnsEmpty() {
    TestObserver<Object> to = new TestObserver<Object>();
    Observable.empty().takeLast(1).subscribe(to);
    to.assertNoValues();
    to.assertNoErrors();
    to.assertTerminated();
    // NO longer assertable
//      s.assertUnsubscribed();
  }

代码示例来源:origin: ReactiveX/RxJava

@Test
public void elementAtOrErrorNoElement() {
  Observable.empty()
    .elementAtOrError(0)
    .test()
    .assertNoValues()
    .assertError(NoSuchElementException.class);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void elementAtIndex1WithDefaultOnEmptySourceObservable() {
  Observable.empty()
    .elementAt(1, 10)
    .toObservable()
    .test()
    .assertResult(10);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void scalarEmptySource() {
  CompletableSubject cs = CompletableSubject.create();
  Observable.empty()
  .switchMapCompletable(Functions.justFunction(cs))
  .test()
  .assertResult();
  assertFalse(cs.hasObservers());
}

相关文章

Observable类方法