use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletablePeekTest method onAfterTerminateCrashes.
@Test
public void onAfterTerminateCrashes() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Completable.complete().doAfterTerminate(new Action() {
@Override
public void run() throws Exception {
throw new TestException();
}
}).test().assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableDisposeOnTest method error.
@Test
public void error() {
TestScheduler scheduler = new TestScheduler();
final int[] call = { 0 };
Completable.error(new TestException()).doOnDispose(new Action() {
@Override
public void run() throws Exception {
call[0]++;
}
}).unsubscribeOn(scheduler).test().assertFailure(TestException.class);
scheduler.triggerActions();
assertEquals(0, call[0]);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableDoOnLifecycleTest method onSubscribeCrash.
@Test
public void onSubscribeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
Action onDispose = mock(Action.class);
doThrow(new TestException("First")).when(onSubscribe).accept(any());
Disposable bs = Disposable.empty();
new Completable() {
@Override
protected void subscribeActual(CompletableObserver observer) {
observer.onSubscribe(bs);
observer.onError(new TestException("Second"));
observer.onComplete();
}
}.doOnLifecycle(onSubscribe, onDispose).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
assertTrue(bs.isDisposed());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
verify(onSubscribe).accept(any());
verify(onDispose, never()).run();
});
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableFromActionTest method fromAction.
@Test
public void fromAction() {
final AtomicInteger atomicInteger = new AtomicInteger();
Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
atomicInteger.incrementAndGet();
}
}).test().assertResult();
assertEquals(1, atomicInteger.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class CompletableFromActionTest method fromActionTwice.
@Test
public void fromActionTwice() {
final AtomicInteger atomicInteger = new AtomicInteger();
Action run = new Action() {
@Override
public void run() throws Exception {
atomicInteger.incrementAndGet();
}
};
Completable.fromAction(run).test().assertResult();
assertEquals(1, atomicInteger.get());
Completable.fromAction(run).test().assertResult();
assertEquals(2, atomicInteger.get());
}
Aggregations