io.reactivex.Flowable.contains()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(323)

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

Flowable.contains介绍

[英]Returns a Single that emits a Boolean that indicates whether the source Publisher emitted a specified item.

Backpressure: The operator honors backpressure from downstream and consumes the source Publisher in an unbounded manner (i.e., without applying backpressure). Scheduler: contains does not operate by default on a particular Scheduler.
[中]返回发出布尔值的单个值,该布尔值指示源发布服务器是否发出指定项。
背压:操作员接受来自下游的背压,并以无限制的方式(即不施加背压)消耗源发布服务器。调度程序:默认情况下,contains不在特定调度程序上运行。

代码示例

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

@Test(expected = NullPointerException.class)
public void containsNull() {
  just1.contains(null);
}

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

@Test
public void testContainsWithEmptyObservable() {
  Single<Boolean> single = Flowable.<String> empty().contains("a");
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, times(1)).onSuccess(false);
  verify(observer, never()).onSuccess(true);
  verify(observer, never()).onError(
      any(Throwable.class));
}

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

@Test
public void testContains() {
  Single<Boolean> single = Flowable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c"
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, times(1)).onSuccess(true);
  verify(observer, never()).onSuccess(false);
  verify(observer, never()).onError(
      any(Throwable.class));
}

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

@Test
public void testContainsWithInexistence() {
  Single<Boolean> single = Flowable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, times(1)).onSuccess(false);
  verify(observer, never()).onSuccess(true);
  verify(observer, never()).onError(
      any(Throwable.class));
}

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

@Test
@Ignore("null values are not allowed")
public void testContainsWithNull() {
  Single<Boolean> single = Flowable.just("a", "b", null).contains(null);
  SingleObserver<Boolean> observer = TestHelper.mockSingleObserver();
  single.subscribe(observer);
  verify(observer, times(1)).onSuccess(true);
  verify(observer, never()).onSuccess(false);
  verify(observer, never()).onError(
      any(Throwable.class));
}

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

@Test
public void testContainsWithEmptyObservableFlowable() {
  Flowable<Boolean> flowable = Flowable.<String> empty().contains("a").toFlowable();
  FlowableSubscriber<Object> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, times(1)).onNext(false);
  verify(subscriber, never()).onNext(true);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

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

@Test
public void testContainsWithInexistenceFlowable() {
  Flowable<Boolean> flowable = Flowable.just("a", "b").contains("c").toFlowable();
  Subscriber<Object> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, times(1)).onNext(false);
  verify(subscriber, never()).onNext(true);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

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

@Test
@Ignore("null values are not allowed")
public void testContainsWithNullFlowable() {
  Flowable<Boolean> flowable = Flowable.just("a", "b", null).contains(null).toFlowable();
  Subscriber<Object> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, times(1)).onNext(true);
  verify(subscriber, never()).onNext(false);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

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

@Test
public void testContainsFlowable() {
  Flowable<Boolean> flowable = Flowable.just("a", "b", "c").contains("b").toFlowable();
  FlowableSubscriber<Boolean> subscriber = TestHelper.mockSubscriber();
  flowable.subscribe(subscriber);
  verify(subscriber, times(1)).onNext(true);
  verify(subscriber, never()).onNext(false);
  verify(subscriber, never()).onError(any(Throwable.class));
  verify(subscriber, times(1)).onComplete();
}

代码示例来源:origin: io.vertx/vertx-rx-java2

protected Completable rxAssertAutoCommit(SQLConnection conn) {
 String testName = UUID.randomUUID().toString();
 return conn.rxExecute(String.format(INSERT_FOLK_SQL, testName))
  .andThen(client.rxGetConnection().flatMapCompletable(other -> {
   return uniqueNames(other).contains(testName)
    .flatMapCompletable(contains -> {
     if (contains) {
      return Completable.complete();
     }
     return Completable.error(new AssertionError("Connection should be back in autocommit mode"));
    })
    .doFinally(other::close);
  }));
}

相关文章

Flowable类方法