use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class FlowableUnsubscribeOnTest method error.
@Test
public void error() {
final int[] calls = { 0 };
Flowable.error(new TestException()).doOnCancel(new Action() {
@Override
public void run() throws Exception {
calls[0]++;
}
}).unsubscribeOn(Schedulers.single()).test().assertFailure(TestException.class);
assertEquals(0, calls[0]);
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class FlowableRepeatTest method noCancelPreviousRepeatUntil.
@Test
public void noCancelPreviousRepeatUntil() {
final AtomicInteger counter = new AtomicInteger();
Flowable<Integer> source = Flowable.just(1).doOnCancel(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
final AtomicInteger times = new AtomicInteger();
source.repeatUntil(new BooleanSupplier() {
@Override
public boolean getAsBoolean() throws Exception {
return times.getAndIncrement() == 4;
}
}).test().assertResult(1, 1, 1, 1, 1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class SingleDoAfterTerminateTest method actionThrows.
@Test
public void actionThrows() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Single.just(1).doAfterTerminate(new Action() {
@Override
public void run() throws Exception {
throw new TestException();
}
}).test().assertResult(1);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class SingleDoOnLifecycleTest 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 Single<Integer>() {
@Override
protected void subscribeActual(SingleObserver<? super Integer> observer) {
observer.onSubscribe(bs);
observer.onError(new TestException("Second"));
observer.onSuccess(1);
}
}.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 SingleDoOnTerminateTest method doOnTerminateError.
@Test
public void doOnTerminateError() {
final AtomicBoolean atomicBoolean = new AtomicBoolean();
Single.error(new TestException()).doOnTerminate(new Action() {
@Override
public void run() {
atomicBoolean.set(true);
}
}).test().assertFailure(TestException.class);
assertTrue(atomicBoolean.get());
}
Aggregations