当前位置: 首页>>代码示例>>Java>>正文


Java BehaviorSubject类代码示例

本文整理汇总了Java中io.reactivex.subjects.BehaviorSubject的典型用法代码示例。如果您正苦于以下问题:Java BehaviorSubject类的具体用法?Java BehaviorSubject怎么用?Java BehaviorSubject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BehaviorSubject类属于io.reactivex.subjects包,在下文中一共展示了BehaviorSubject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testClose_waitForCommands

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test
public void testClose_waitForCommands() {
    BehaviorSubject<Boolean> idler = BehaviorSubject.createDefault(false);
    when(cmdProcessor.isIdle()).thenReturn(idler);

    RxCmdShell shell = new RxCmdShell(builder);
    shell.open().test().awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().values().get(0);
    shell.isAlive().test().awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().assertValue(true);

    shell.close().test().awaitDone(1, TimeUnit.SECONDS).assertTimeout();

    idler.onNext(true);

    shell.close().test().awaitDone(1, TimeUnit.SECONDS).assertNoTimeout().assertValue(0);

    verify(cmdProcessor).isIdle();
    verify(rxShellSession).close();
}
 
开发者ID:d4rken,项目名称:RxShell,代码行数:19,代码来源:RxCmdShellTest.java

示例2: testBindUntilLifecycleEvent

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test
public void testBindUntilLifecycleEvent() {
    BehaviorSubject<Lifecycle.Event> lifecycle = BehaviorSubject.create();

    TestObserver<Object> testObserver =
            observable.compose(RxLifecycle.bindUntilEvent(lifecycle, Lifecycle.Event.ON_STOP)).test();

    lifecycle.onNext(Lifecycle.Event.ON_CREATE);
    testObserver.assertNotComplete();
    lifecycle.onNext(Lifecycle.Event.ON_START);
    testObserver.assertNotComplete();
    lifecycle.onNext(Lifecycle.Event.ON_RESUME);
    testObserver.assertNotComplete();
    lifecycle.onNext(Lifecycle.Event.ON_PAUSE);
    testObserver.assertNotComplete();
    lifecycle.onNext(Lifecycle.Event.ON_STOP);
    testObserver.assertComplete();
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:19,代码来源:RxLifecycleTest.java

示例3: testBindUntilFragmentEvent

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test
public void testBindUntilFragmentEvent() {
    BehaviorSubject<FragmentEvent> lifecycle = BehaviorSubject.create();

    TestObserver<Object> testObserver =
        observable.compose(RxLifecycle.bindUntilEvent(lifecycle, FragmentEvent.STOP)).test();

    lifecycle.onNext(FragmentEvent.ATTACH);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.CREATE);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.CREATE_VIEW);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.START);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.RESUME);
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.PAUSE);
    testObserver.assertNotComplete();
    testObserver.assertNotComplete();
    lifecycle.onNext(FragmentEvent.STOP);
    testObserver.assertComplete();
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:24,代码来源:RxLifecycleTest.java

示例4: testBindUntilActivityEvent

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test
public void testBindUntilActivityEvent() {
    BehaviorSubject<ActivityEvent> lifecycle = BehaviorSubject.create();

    TestObserver<Object> testObserver =
        observable.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.STOP)).test();

    lifecycle.onNext(ActivityEvent.CREATE);
    testObserver.assertNotComplete();
    lifecycle.onNext(ActivityEvent.START);
    testObserver.assertNotComplete();
    lifecycle.onNext(ActivityEvent.RESUME);
    testObserver.assertNotComplete();
    lifecycle.onNext(ActivityEvent.PAUSE);
    testObserver.assertNotComplete();
    lifecycle.onNext(ActivityEvent.STOP);
    testObserver.assertComplete();
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:19,代码来源:RxLifecycleTest.java

示例5: doSomeWork

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
/**
 * 当观察者订阅BehaviorSubject时,它开始发射原始Observable最近发射的数据
 * (如果此时还 没有收到任何数据,它会发射一个默认值),然后继续发射其它任何来自原始Observable的数据。
 * 然而,如果原始的Observable因为发生了一个错误而终止,BehaviorSubject将不会发射任何数据,只是简单的向前传递这个错误通知。
 */
private void doSomeWork() {

    BehaviorSubject<Integer> source = BehaviorSubject.create();

    source.subscribe(getFirstObserver()); // it will get 1, 2, 3, 4 and onComplete

    source.onNext(1);
    source.onNext(2);
    source.onNext(3);

    /*
     * it will emit 3(last emitted), 4 and onComplete for second observer also.
     */
    source.subscribe(getSecondObserver());

    source.onNext(4);
    source.onComplete();

}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:25,代码来源:BehaviorSubjectExampleActivity.java

示例6: autoDispose_withProvider_success

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withProvider_success() {
  RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
  MaybeSubject<Integer> source = MaybeSubject.create();
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
  source.as(AutoDispose.<Integer>autoDisposable(provider))
      .subscribe(o);
  o.takeSubscribe();

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  lifecycle.onNext(1);

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  source.onSuccess(3);
  o.takeSuccess();

  o.assertNoMoreEvents();
  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:25,代码来源:AutoDisposeMaybeObserverTest.java

示例7: autoDispose_withLifecycleProvider_completion

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withLifecycleProvider_completion() {
  RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
  MaybeSubject<Integer> source = MaybeSubject.create();
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
  source.as(AutoDispose.<Integer>autoDisposable(provider))
      .subscribe(o);
  o.takeSubscribe();

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  lifecycle.onNext(1);

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  source.onComplete();
  o.assertOnComplete();

  o.assertNoMoreEvents();
  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:25,代码来源:AutoDisposeMaybeObserverTest.java

示例8: autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) { }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  MaybeSubject<Integer> source = MaybeSubject.create();
  TestObserver<Integer> o = source
          .as(AutoDispose.<Integer>autoDisposable(provider))
          .test();

  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:17,代码来源:AutoDisposeMaybeObserverTest.java

示例9: autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Noop
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  lifecycle.onNext(1);
  lifecycle.onNext(2);
  lifecycle.onNext(3);
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  MaybeSubject<Integer> source = MaybeSubject.create();
  TestObserver<Integer> o = source
          .as(AutoDispose.<Integer>autoDisposable(provider))
          .test();

  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:22,代码来源:AutoDisposeMaybeObserverTest.java

示例10: autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithWrappedExp

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithWrappedExp() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Wrap in an IllegalStateException so we can verify this is the exception we see on the
      // other side
      throw new IllegalStateException(e);
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  MaybeSubject<Integer> source = MaybeSubject.create();
  TestObserver<Integer> o = source
          .as(AutoDispose.<Integer>autoDisposable(provider))
          .test();

  o.assertNoValues();
  o.assertError(new Predicate<Throwable>() {
    @Override public boolean test(Throwable throwable) {
      return throwable instanceof IllegalStateException
          && throwable.getCause() instanceof OutsideLifecycleException;
    }
  });
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:24,代码来源:AutoDisposeMaybeObserverTest.java

示例11: autoDispose_withLifecycleProvider_completion

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withLifecycleProvider_completion() {
  RecordingObserver<Integer> o = new RecordingObserver<>(LOGGER);
  CompletableSubject source = CompletableSubject.create();
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  LifecycleScopeProvider<Integer> provider = makeLifecycleProvider(lifecycle);
  source.as(autoDisposable(provider))
      .subscribe(o);
  o.takeSubscribe();

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  lifecycle.onNext(1);

  assertThat(source.hasObservers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  source.onComplete();
  o.assertOnComplete();

  o.assertNoMoreEvents();
  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:25,代码来源:AutoDisposeCompletableObserverTest.java

示例12: autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withProviderAndNoOpPlugin_withoutStarting_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) { }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  CompletableSubject source = CompletableSubject.create();
  TestObserver<Void> o = source
          .as(autoDisposable(provider))
          .test();

  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:17,代码来源:AutoDisposeCompletableObserverTest.java

示例13: autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withProviderAndNoOpPlugin_afterEnding_shouldFailSilently() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Noop
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.createDefault(0);
  lifecycle.onNext(1);
  lifecycle.onNext(2);
  lifecycle.onNext(3);
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  CompletableSubject source = CompletableSubject.create();
  TestObserver<Void> o = source
          .as(autoDisposable(provider))
          .test();

  assertThat(source.hasObservers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
  o.assertNoValues();
  o.assertNoErrors();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:22,代码来源:AutoDisposeCompletableObserverTest.java

示例14: autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithWrappedExp

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withProviderAndPlugin_withoutStarting_shouldFailWithWrappedExp() {
  AutoDisposePlugins.setOutsideLifecycleHandler(new Consumer<OutsideLifecycleException>() {
    @Override public void accept(OutsideLifecycleException e) {
      // Wrap in an IllegalStateException so we can verify this is the exception we see on the
      // other side
      throw new IllegalStateException(e);
    }
  });
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  TestObserver<Void> o = CompletableSubject.create()
            .as(autoDisposable(provider))
            .test();

  o.assertNoValues();
  o.assertError(new Predicate<Throwable>() {
    @Override public boolean test(Throwable throwable) {
      return throwable instanceof IllegalStateException
          && throwable.getCause() instanceof OutsideLifecycleException;
    }
  });
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:23,代码来源:AutoDisposeCompletableObserverTest.java

示例15: autoDispose_withProvider_withoutStartingLifecycle_shouldFail

import io.reactivex.subjects.BehaviorSubject; //导入依赖的package包/类
@Test public void autoDispose_withProvider_withoutStartingLifecycle_shouldFail() {
  BehaviorSubject<Integer> lifecycle = BehaviorSubject.create();
  TestSubscriber<Integer> firstSubscriber = new TestSubscriber<>();
  TestSubscriber<Integer> secondSubscriber = new TestSubscriber<>();
  LifecycleScopeProvider<Integer> provider = TestUtil.makeLifecycleProvider(lifecycle);
  //noinspection unchecked
  Subscriber<Integer>[] subscribers = new Subscriber[] {firstSubscriber, secondSubscriber};

  Flowable.just(1, 2)
      .parallel(DEFAULT_PARALLELISM)
      .as(AutoDispose.<Integer>autoDisposable(provider))
      .subscribe(subscribers);

  List<Throwable> errors1 = firstSubscriber.errors();
  assertThat(errors1).hasSize(1);
  assertThat(errors1.get(0)).isInstanceOf(LifecycleNotStartedException.class);

  List<Throwable> errors2 = secondSubscriber.errors();
  assertThat(errors2).hasSize(1);
  assertThat(errors2.get(0)).isInstanceOf(LifecycleNotStartedException.class);
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:22,代码来源:AutoDisposeParallelFlowableTest.java


注:本文中的io.reactivex.subjects.BehaviorSubject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。