本文整理匯總了Java中io.reactivex.subscribers.TestSubscriber.assertError方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.assertError方法的具體用法?Java TestSubscriber.assertError怎麽用?Java TestSubscriber.assertError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.subscribers.TestSubscriber
的用法示例。
在下文中一共展示了TestSubscriber.assertError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onErrorDelegates
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void onErrorDelegates() {
ClientCallStreamObserver<Object> obs = mock(ClientCallStreamObserver.class);
RxConsumerStreamObserver rxObs = new RxConsumerStreamObserver();
Subscriber<Object> sub = mock(Subscriber.class);
rxObs.beforeStart(obs);
rxObs.getRxConsumer().subscribe(sub);
TestSubscriber<Object> testSubscriber = ((Flowable<Object>)rxObs.getRxConsumer()).test();
Throwable obj = new Exception();
rxObs.onError(obj);
testSubscriber.awaitTerminalEvent(3, TimeUnit.SECONDS);
testSubscriber.assertError(obj);
}
示例2: testGetOneWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testGetOneWithError(){
testStore.shouldThrowError(true);
models.clear();
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(10));
list.add(new TestModel(20));
list.add(new TestModel(30));
memoryStore.insertOrUpdate(list);
TestSubscriber<Optional<TestModel>> observer = new TestSubscriber<>();
disposables.add(testStore.getOne()
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(2, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("getOne.error");
testStore.shouldThrowError(false);
Assert.assertEquals(3, models.size());
}
示例3: testInsertListWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testInsertListWithError(){
models.clear();
testStore.shouldThrowError(true); // enable error
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(1));
list.add(new TestModel(2));
list.add(new TestModel(3));
TestSubscriber<Optional<List<TestModel>>> observer = new TestSubscriber<>();
disposables.add(testStore.insert(list)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(2, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("insert.error");
testStore.shouldThrowError(false); // disable error
Assert.assertEquals(0, models.size()); // should have been cleared
}
示例4: testInsertWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testInsertWithError(){
models.clear();
testStore.shouldThrowError(true); // enable error
TestModel model = new TestModel(99);
TestSubscriber<Optional<TestModel>> observer = new TestSubscriber<>();
disposables.add(testStore.insert(model)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(2, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("insertSingle.error");
testStore.shouldThrowError(false); // disable error
Assert.assertEquals(0, models.size());
}
示例5: testDeleteAllWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testDeleteAllWithError(){
testStore.shouldThrowError(true);
models.clear();
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(1));
list.add(new TestModel(2));
list.add(new TestModel(3));
memoryStore.insertOrUpdate(list);
TestSubscriber<Integer> observer = new TestSubscriber<>();
disposables.add(testStore.deleteAll()
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(5, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("deleteAll.error");
testStore.shouldThrowError(false); // disable error
Assert.assertEquals(3, models.size());
}
示例6: testInsertOrUpdateForInsertWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testInsertOrUpdateForInsertWithError(){
models.clear();
testStore.shouldThrowError(true);
final TestModel model = new TestModel(99);
model.setAvailable(true);
TestSubscriber<Optional<TestModel>> observer = new TestSubscriber<>();
disposables.add(testStore.insertOrUpdate(model)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(4, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("insertOrUpdateSingle.error");
testStore.shouldThrowError(false);
Assert.assertEquals(0, models.size());
}
示例7: testErrorHandlingInValueProvider
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testErrorHandlingInValueProvider()
{
// setup
final AtomicBoolean missHandlerCalled = new AtomicBoolean(false);
TestSubscriber<Integer> testSubscriber1 = new TestSubscriber<>();
subscribe(source.get("hello"), testSubscriber1);
source.onNext("hello", new Callable<Integer>() {
@Override
public Integer call() throws Exception
{
throw new RuntimeException("Boom");
}
}, new Action() {
@Override
public void run()
{
missHandlerCalled.set(true);
}
});
testSubscriber1.assertError(RuntimeException.class);
}
示例8: oneToMany
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void oneToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloResponse> resp = stub.sayHelloRespStream(Single.just(HelloRequest.getDefaultInstance()));
TestSubscriber<HelloResponse> test = resp
.doOnNext(msg -> System.out.println(msg))
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.doOnComplete(() -> System.out.println("Completed"))
.doOnCancel(() -> System.out.println("Client canceled"))
.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus() == Status.INTERNAL);
}
示例9: manyToMany
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void manyToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloResponse> resp = stub.sayHelloBothStream(Flowable.just(HelloRequest.getDefaultInstance()));
TestSubscriber<HelloResponse> test = resp.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus() == Status.INTERNAL);
}
示例10: oneToMany
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void oneToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloResponse> resp = stub.sayHelloRespStream(Single.just(HelloRequest.getDefaultInstance()));
TestSubscriber<HelloResponse> test = resp
.doOnNext(msg -> System.out.println(msg))
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.doOnComplete(() -> System.out.println("Completed"))
.doOnCancel(() -> System.out.println("Client canceled"))
.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus().getCode() == Status.Code.INTERNAL);
}
示例11: manyToMany
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void manyToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloRequest> req = Flowable.just(HelloRequest.getDefaultInstance());
Flowable<HelloResponse> resp = stub.sayHelloBothStream(req);
TestSubscriber<HelloResponse> test = resp.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus().getCode() == Status.Code.CANCELLED);
}
示例12: testGetAllWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testGetAllWithError(){
models.clear();
testStore.shouldThrowError(true); // enable error
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(1));
list.add(new TestModel(2));
list.add(new TestModel(3));
memoryStore.insertOrUpdate(list);
TestSubscriber<Optional<List<TestModel>>> observer = new TestSubscriber<>();
disposables.add(testStore.getAll(null, null)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(2, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("getAll.error");
testStore.shouldThrowError(false); // disable error
Assert.assertEquals(models.size(), 3);
int sum = 0;
for(TestModel tm : models){
sum += tm.getId();
}
Assert.assertEquals(6, sum);
}
示例13: testDeleteSingleWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testDeleteSingleWithError(){
models.clear();
testStore.shouldThrowError(true);
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(1));
list.add(new TestModel(2));
list.add(new TestModel(3));
memoryStore.insertOrUpdate(list);
TestModel model = new TestModel(2);
TestSubscriber<Integer> observer = new TestSubscriber<>();
disposables.add(testStore.delete(model)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(2, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("deleteSingle.error");
int sum = 0;
for(TestModel tm : models){
sum += tm.getId();
}
testStore.shouldThrowError(false); // disable error
Assert.assertEquals(3, models.size());
Assert.assertEquals(6, sum);
}
示例14: testInsertOrUpdateForUpdateWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testInsertOrUpdateForUpdateWithError(){
models.clear();
final TestModel model = new TestModel(99);
model.setAvailable(true); // should be rollback to this version
models.add(model);
testStore.shouldThrowError(true);
final TestModel otherModelReferenceWithSameId = new TestModel(99);
otherModelReferenceWithSameId.setAvailable(false);
TestSubscriber<Optional<TestModel>> observer = new TestSubscriber<>();
disposables.add(testStore.insertOrUpdate(otherModelReferenceWithSameId)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(5, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("insertOrUpdateSingle.error");
testStore.shouldThrowError(false);
final TestModel output = models.get(0);
Assert.assertEquals(1, models.size());
Assert.assertNotNull(output);
Assert.assertTrue(output.isAvailable()); // rollback to first version
}
示例15: testInsertOrUpdateManyWithError
import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testInsertOrUpdateManyWithError(){
models.clear();
testStore.shouldThrowError(true);
List<TestModel> list = new ArrayList<>();
list.add(new TestModel(10));
list.add(new TestModel(20));
list.add(new TestModel(30));
memoryStore.insertOrUpdate(list);
List<TestModel> listToInsertOrUpdate = new ArrayList<>();
final TestModel first = new TestModel(20);
first.setAvailable(true);
final TestModel second = new TestModel(99);
second.setAvailable(true);
listToInsertOrUpdate.add(first);
listToInsertOrUpdate.add(second);
TestSubscriber<Optional<List<TestModel>>> observer = new TestSubscriber<>();
disposables.add(testStore.insertOrUpdate(listToInsertOrUpdate)
.subscribeOn(Schedulers.io())
.subscribeWith(observer));
observer.awaitTerminalEvent(5, SECONDS);
observer.assertError(Throwable.class);
observer.assertErrorMessage("insertOrUpdate.error");
testStore.shouldThrowError(false);
for(TestModel tm : MemoryDao.models){
Assert.assertFalse(tm.isAvailable());
}
Assert.assertEquals(3, MemoryDao.models.size());
}