本文整理汇总了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");
}