當前位置: 首頁>>代碼示例>>Java>>正文


Java PublishSubject.onError方法代碼示例

本文整理匯總了Java中rx.subjects.PublishSubject.onError方法的典型用法代碼示例。如果您正苦於以下問題:Java PublishSubject.onError方法的具體用法?Java PublishSubject.onError怎麽用?Java PublishSubject.onError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rx.subjects.PublishSubject的用法示例。


在下文中一共展示了PublishSubject.onError方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: error

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void error() {
  TestScheduler scheduler = new TestScheduler();
  PublishSubject<Integer> subject = PublishSubject.create();
  RecordingObserver<Integer> o = new RecordingObserver<>();
  subject
      .lift(new OperatorNormalize<Integer>(1, TimeUnit.SECONDS, scheduler))
      .subscribe(o);

  // First emits immediately
  subject.onNext(0);
  o.takeNext();

  subject.onNext(1);
  subject.onError(new RuntimeException("Blah"));
  o.assertNoMoreEvents();

  scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
  o.takeNext();
  assertThat(o.takeError()).isInstanceOf(RuntimeException.class);
}
 
開發者ID:hzsweers,項目名稱:RxNormalize,代碼行數:22,代碼來源:OperatorNormalizeTest.java

示例2: testEmitsErrors

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void testEmitsErrors() {
  final PublishSubject<Integer> source = PublishSubject.create();
  final Observable<Throwable> result = source
    .materialize()
    .compose(Transformers.errors());

  final TestSubscriber<Throwable> resultTest = new TestSubscriber<>();
  result.subscribe(resultTest);

  source.onNext(1);
  resultTest.assertNoValues();

  // Only emit when an error is thrown.
  source.onError(new Throwable());
  resultTest.assertValueCount(1);
}
 
開發者ID:kickstarter,項目名稱:android-oss,代碼行數:18,代碼來源:ErrorsTransformerTest.java

示例3: testErrorsDoNotEmit

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void testErrorsDoNotEmit() {
  final PublishSubject<Integer> source = PublishSubject.create();
  final Observable<Integer> result = source
    .materialize()
    .compose(Transformers.values());

  final TestSubscriber<Integer> resultTest = new TestSubscriber<>();
  result.subscribe(resultTest);

  //
  source.onNext(1);
  resultTest.assertValues(1);

  // An error in the source stream should not emit values.
  source.onError(new Throwable());

  resultTest.assertValues(1);
}
 
開發者ID:kickstarter,項目名稱:android-oss,代碼行數:20,代碼來源:ValuesTransformerTest.java

示例4: refreshError

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void refreshError() throws Exception {
    PublishSubject<Reddit> subject = PublishSubject.create();
    Mockito.doReturn(subject.asObservable().toList())
            .when(mRepository)
            .getReddits(Mockito.anyString());
    mViewModel.refresh();
    Mockito.verify(mRepository).getReddits("test");
    Assert.assertThat(mViewModel.errorText.get(), IsNull.nullValue());
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(true));
    subject.onError(new Exception("error text"));
    Assert.assertThat(mViewModel.isLoading.get(), Is.is(false));
    Assert.assertThat(mViewModel.errorText.get(), IsEqual.equalTo("error text"));
}
 
開發者ID:DanielSerdyukov,項目名稱:droidcon2016,代碼行數:15,代碼來源:RedditListViewModelTest.java

示例5: testErrorDoesNotEmitACompletedNotification

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
@Test
public void testErrorDoesNotEmitACompletedNotification() {
  final PublishSubject<Integer> source = PublishSubject.create();
  final Observable<Void> result = source
    .materialize()
    .compose(Transformers.completed());

  final TestSubscriber<Void> resultTest = new TestSubscriber<>();
  result.subscribe(resultTest);

  source.onError(new Throwable());
  resultTest.assertValueCount(0);
}
 
開發者ID:kickstarter,項目名稱:android-oss,代碼行數:14,代碼來源:CompletedTransformerTest.java

示例6: onError

import rx.subjects.PublishSubject; //導入方法依賴的package包/類
void onError(int requestCode, ActivityNotFoundException exception) {
    PublishSubject<ActivityResult> subject = results.remove(requestCode);
    subject.onError(exception);
}
 
開發者ID:NateWickstrom,項目名稱:RxActivityResult,代碼行數:5,代碼來源:RxActivityResult.java


注:本文中的rx.subjects.PublishSubject.onError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。