本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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"));
}
示例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);
}
示例6: onError
import rx.subjects.PublishSubject; //導入方法依賴的package包/類
void onError(int requestCode, ActivityNotFoundException exception) {
PublishSubject<ActivityResult> subject = results.remove(requestCode);
subject.onError(exception);
}