use of io.reactivex.rxjava3.functions.Consumer in project RxRelay by JakeWharton.
the class PublishRelayTest method testNestedSubscribe.
@Test
@SuppressWarnings("CheckReturnValue")
public void testNestedSubscribe() {
final PublishRelay<Integer> s = PublishRelay.create();
final AtomicInteger countParent = new AtomicInteger();
final AtomicInteger countChildren = new AtomicInteger();
final AtomicInteger countTotal = new AtomicInteger();
final ArrayList<String> list = new ArrayList<String>();
s.flatMap(new Function<Integer, Observable<String>>() {
@Override
public Observable<String> apply(final Integer v) {
countParent.incrementAndGet();
// then subscribe to subject again (it will not receive the previous value)
return s.map(new Function<Integer, String>() {
@Override
public String apply(Integer v2) {
countChildren.incrementAndGet();
return "Parent: " + v + " Child: " + v2;
}
});
}
}).subscribe(new Consumer<String>() {
@Override
public void accept(String v) {
countTotal.incrementAndGet();
list.add(v);
}
});
for (int i = 0; i < 10; i++) {
s.accept(i);
}
// System.out.println("countParent: " + countParent.get());
// System.out.println("countChildren: " + countChildren.get());
// System.out.println("countTotal: " + countTotal.get());
// 9+8+7+6+5+4+3+2+1+0 == 45
assertEquals(45, list.size());
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class FlowableTimeoutWithSelectorTest method timeoutConsumerIsDisposed.
@Test
public void timeoutConsumerIsDisposed() {
TimeoutConsumer consumer = new TimeoutConsumer(0, null);
assertFalse(consumer.isDisposed());
consumer.dispose();
assertTrue(consumer.isDisposed());
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class FlowableSwitchIfEmptyTest method switchWhenNotEmpty.
@Test
public void switchWhenNotEmpty() throws Exception {
final AtomicBoolean subscribed = new AtomicBoolean(false);
final Flowable<Integer> flowable = Flowable.just(4).switchIfEmpty(Flowable.just(2).doOnSubscribe(new Consumer<Subscription>() {
@Override
public void accept(Subscription s) {
subscribed.set(true);
}
}));
assertEquals(4, flowable.blockingSingle().intValue());
assertFalse(subscribed.get());
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class SingleSafeSubscribeTest method onErrorCrash.
@Test
public void onErrorCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
doThrow(new TestException()).when(consumer).onError(any());
new Single<Integer>() {
@Override
protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
// none of the following should arrive at the consumer
observer.onError(new IOException());
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onError(any(IOException.class));
order.verifyNoMoreInteractions();
TestHelper.assertError(errors, 0, CompositeException.class);
CompositeException compositeException = (CompositeException) errors.get(0);
TestHelper.assertError(compositeException.getExceptions(), 0, IOException.class);
TestHelper.assertError(compositeException.getExceptions(), 1, TestException.class);
});
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class SingleSafeSubscribeTest method normalError.
@Test
public void normalError() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
Single.<Integer>error(new TestException()).safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onError(any(TestException.class));
order.verifyNoMoreInteractions();
assertTrue("" + errors, errors.isEmpty());
});
}
Aggregations