本文整理匯總了Java中io.reactivex.subjects.PublishSubject.subscribeWith方法的典型用法代碼示例。如果您正苦於以下問題:Java PublishSubject.subscribeWith方法的具體用法?Java PublishSubject.subscribeWith怎麽用?Java PublishSubject.subscribeWith使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.subjects.PublishSubject
的用法示例。
在下文中一共展示了PublishSubject.subscribeWith方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: error
import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test public void error() {
PublishSubject subject = PublishSubject.create();
TestObserver sub = new TestObserver<>();
subject.subscribeWith(sub);
Exception originalException = new RuntimeException("I am the original Exception");
Exception expectedException =
new IllegalStateException("View intents must not throw errors", originalException);
try {
Observable.error(originalException).subscribe(new DisposableIntentObserver(subject));
Assert.fail("Exception expected");
} catch (Exception e) {
Throwable cause = e.getCause();
Assert.assertEquals(expectedException.getMessage(), cause.getMessage());
Assert.assertEquals(originalException, cause.getCause());
}
sub.assertNotComplete().assertNoValues();
}
示例2: forwardOnNextAndOnCompleteToPublishShubject
import io.reactivex.subjects.PublishSubject; //導入方法依賴的package包/類
@Test public void forwardOnNextAndOnCompleteToPublishShubject() {
PublishSubject<String> subject = PublishSubject.create();
TestObserver<String> sub = new TestObserver<>();
subject.subscribeWith(sub);
Observable.just("Hello").subscribe(new DisposableIntentObserver<String>(subject));
sub.assertNoErrors().assertComplete().assertResult("Hello");
}