use of io.reactivex.observers.TestObserver 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.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!errorRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
latch.countDown();
}
});
TestObserver<Void> observer = new TestObserver<>();
final RuntimeException e = new RuntimeException();
service.completable().subscribe(new ForwardingCompletableObserver(observer) {
@Override
public void onComplete() {
throw e;
}
});
latch.await(1, SECONDS);
assertThat(errorRef.get()).isSameAs(e);
}
use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.
the class RxPermissionsTest method eachSubscriptionCombined_trigger_granted.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscriptionCombined_trigger_granted() {
TestObserver<Permission> sub = new TestObserver<>();
String permission = Manifest.permission.READ_PHONE_STATE;
when(mRxPermissions.isGranted(permission)).thenReturn(false);
int[] result = new int[] { PackageManager.PERMISSION_GRANTED };
PublishSubject<Object> trigger = PublishSubject.create();
trigger.compose(mRxPermissions.ensureEachCombined(permission)).subscribe(sub);
trigger.onNext(1);
mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
sub.assertNoErrors();
sub.assertNotTerminated();
sub.assertValue(new Permission(permission, true));
}
use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.
the class RxPermissionsTest method subscription_trigger_granted.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_trigger_granted() {
TestObserver<Boolean> sub = new TestObserver<>();
String permission = Manifest.permission.READ_PHONE_STATE;
when(mRxPermissions.isGranted(permission)).thenReturn(false);
int[] result = new int[] { PackageManager.PERMISSION_GRANTED };
PublishSubject<Object> trigger = PublishSubject.create();
trigger.compose(mRxPermissions.ensure(permission)).subscribe(sub);
trigger.onNext(1);
mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
sub.assertNoErrors();
sub.assertNotTerminated();
sub.assertValue(true);
}
use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.
the class RxPermissionsTest method eachSubscription_trigger_granted.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_trigger_granted() {
TestObserver<Permission> sub = new TestObserver<>();
String permission = Manifest.permission.READ_PHONE_STATE;
when(mRxPermissions.isGranted(permission)).thenReturn(false);
int[] result = new int[] { PackageManager.PERMISSION_GRANTED };
PublishSubject<Object> trigger = PublishSubject.create();
trigger.compose(mRxPermissions.ensureEach(permission)).subscribe(sub);
trigger.onNext(1);
mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
sub.assertNoErrors();
sub.assertNotTerminated();
sub.assertValue(new Permission(permission, true));
}
use of io.reactivex.observers.TestObserver in project RxPermissions by tbruyelle.
the class RxPermissionsTest method subscription_granted.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_granted() {
TestObserver<Boolean> sub = new TestObserver<>();
String permission = Manifest.permission.READ_PHONE_STATE;
when(mRxPermissions.isGranted(permission)).thenReturn(false);
int[] result = new int[] { PackageManager.PERMISSION_GRANTED };
trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);
mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
sub.assertNoErrors();
sub.assertTerminated();
sub.assertValue(true);
}
Aggregations