use of rx.observers.TestSubscriber in project sqlbrite by square.
the class QueryTest method mapToListIgnoresNullCursor.
@Test
public void mapToListIgnoresNullCursor() {
Query nully = new Query() {
@Nullable
@Override
public Cursor run() {
return null;
}
};
TestSubscriber<List<Employee>> subscriber = new TestSubscriber<>();
Observable.just(nully).lift(Query.mapToList(Employee.MAPPER)).subscribe(subscriber);
subscriber.assertNoValues();
subscriber.assertCompleted();
}
use of rx.observers.TestSubscriber in project sqlbrite by square.
the class QueryTest method mapToOneOrDefaultReturnsDefaultWhenNullCursor.
@Test
public void mapToOneOrDefaultReturnsDefaultWhenNullCursor() {
Employee defaultEmployee = new Employee("bob", "Bob Bobberson");
Query nully = new Query() {
@Nullable
@Override
public Cursor run() {
return null;
}
};
TestSubscriber<Employee> subscriber = new TestSubscriber<>();
Observable.just(nully).lift(Query.mapToOneOrDefault(Employee.MAPPER, defaultEmployee)).subscribe(subscriber);
subscriber.assertValues(defaultEmployee);
subscriber.assertCompleted();
}
use of rx.observers.TestSubscriber in project retrofit by square.
the class AsyncTest method success.
@Test
public void success() throws InterruptedException {
TestSubscriber<Void> subscriber = new TestSubscriber<>();
service.completable().subscribe(subscriber);
assertFalse(subscriber.awaitValueCount(1, 1, SECONDS));
server.enqueue(new MockResponse());
subscriber.awaitTerminalEvent(1, SECONDS);
subscriber.assertCompleted();
}
use of rx.observers.TestSubscriber in project retrofit by square.
the class AsyncTest method throwingInOnCompleteDeliveredToPlugin.
@Test
public void throwingInOnCompleteDeliveredToPlugin() throws InterruptedException {
server.enqueue(new MockResponse());
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (!errorRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
latch.countDown();
}
});
final TestSubscriber<Void> subscriber = new TestSubscriber<>();
final RuntimeException e = new RuntimeException();
service.completable().unsafeSubscribe(new AsyncCompletableSubscriber() {
@Override
public void onCompleted() {
throw e;
}
@Override
public void onError(Throwable t) {
subscriber.onError(t);
}
});
latch.await(1, SECONDS);
assertThat(errorRef.get()).isSameAs(e);
}
use of rx.observers.TestSubscriber in project retrofit by square.
the class AsyncTest method bodyThrowingInOnErrorDeliveredToPlugin.
@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404));
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
@Override
public void handleError(Throwable throwable) {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
latch.countDown();
}
});
final TestSubscriber<Void> subscriber = new TestSubscriber<>();
final RuntimeException e = new RuntimeException();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
service.completable().unsafeSubscribe(new AsyncCompletableSubscriber() {
@Override
public void onCompleted() {
subscriber.onCompleted();
}
@Override
public void onError(Throwable t) {
errorRef.set(t);
throw e;
}
});
latch.await(1, SECONDS);
//noinspection ThrowableResultOfMethodCallIgnored
CompositeException composite = (CompositeException) pluginRef.get();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Aggregations