Search in sources :

Example 46 with Consumer

use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.

the class MaybeTest method usingNonEager.

@Test
public void usingNonEager() {
    final AtomicInteger disposeCount = new AtomicInteger();
    Maybe.using(Functions.justSupplier(1), new Function<Integer, MaybeSource<Integer>>() {

        @Override
        public MaybeSource<Integer> apply(Integer v) throws Exception {
            return Maybe.just(v);
        }
    }, new Consumer<Integer>() {

        @Override
        public void accept(Integer d) throws Exception {
            disposeCount.set(d);
        }
    }, false).map(new Function<Integer, Object>() {

        @Override
        public String apply(Integer v) throws Exception {
            return "" + disposeCount.get() + v * 10;
        }
    }).test().assertResult("010");
    assertEquals(1, disposeCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArgsToString(io.reactivex.rxjava3.internal.operators.flowable.FlowableZipTest.ArgsToString) IOException(java.io.IOException) Test(org.junit.Test)

Example 47 with Consumer

use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.

the class ConnectableObservable method connect.

/**
 * Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying
 * {@link Observable} to its {@link Observer}s.
 * <p>
 * To disconnect from a synchronous source, use the {@link #connect(Consumer)} method.
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>The behavior is determined by the implementor of this abstract class.</dd>
 * </dl>
 *
 * @return the {@link Disposable} representing the connection
 * @see <a href="http://reactivex.io/documentation/operators/connect.html">ReactiveX documentation: Connect</a>
 */
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable connect() {
    ConnectConsumer cc = new ConnectConsumer();
    connect(cc);
    return cc.disposable;
}
Also used : ConnectConsumer(io.reactivex.rxjava3.internal.util.ConnectConsumer)

Example 48 with Consumer

use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.

the class CompletableBlockingSubscribeTest method twoArgErrorFails.

@Test
public void twoArgErrorFails() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        Action action = mock(Action.class);
        @SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
        doThrow(new TestException()).when(consumer).accept(any());
        Completable.error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation(), true).blockingSubscribe(action, consumer);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        verify(action, never()).run();
        verify(consumer).accept(any(TestException.class));
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 49 with Consumer

use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.

the class CompletableBlockingSubscribeTest method twoArgErrorAsync.

@Test
public void twoArgErrorAsync() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        Action action = mock(Action.class);
        @SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
        Completable.error(new TestException()).delay(50, TimeUnit.MILLISECONDS, Schedulers.computation(), true).blockingSubscribe(action, consumer);
        assertTrue("" + errors, errors.isEmpty());
        verify(action, never()).run();
        verify(consumer).accept(any(TestException.class));
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 50 with Consumer

use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.

the class CompletableBlockingSubscribeTest method twoArgCompleteFails.

@Test
public void twoArgCompleteFails() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        Action action = mock(Action.class);
        doThrow(new TestException()).when(action).run();
        @SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
        Completable.complete().blockingSubscribe(action, consumer);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        verify(action).run();
        verify(consumer, never()).accept(any());
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)98 TestException (io.reactivex.rxjava3.exceptions.TestException)57 Disposable (io.reactivex.rxjava3.disposables.Disposable)39 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)22 IOException (java.io.IOException)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 InOrder (org.mockito.InOrder)17 TestObserver (io.reactivex.rxjava3.observers.TestObserver)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)8 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Observable (io.reactivex.rxjava3.core.Observable)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)5 Consumer (io.reactivex.rxjava3.functions.Consumer)5 CompositeException (io.reactivex.rxjava3.exceptions.CompositeException)4 ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Observer (io.reactivex.rxjava3.core.Observer)3 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)3 ArgsToString (io.reactivex.rxjava3.internal.operators.flowable.FlowableZipTest.ArgsToString)3