Search in sources :

Example 6 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class ObservableFlatMapStreamTest method eventsIgnoredAfterDispose.

@Test
public void eventsIgnoredAfterDispose() {
    AtomicInteger calls = new AtomicInteger();
    new Observable<Integer>() {

        @Override
        protected void subscribeActual(@NonNull Observer<? super Integer> observer) {
            observer.onSubscribe(Disposable.empty());
            observer.onNext(1);
            observer.onNext(2);
            observer.onComplete();
        }
    }.flatMapStream(v -> {
        calls.getAndIncrement();
        return Stream.of(1);
    }).take(1).test().assertResult(1);
    assertEquals(1, calls.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.subjects(io.reactivex.rxjava3.subjects) Iterator(java.util.Iterator) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) NonNull(io.reactivex.rxjava3.annotations.NonNull) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestObserver(io.reactivex.rxjava3.observers.TestObserver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposable(io.reactivex.rxjava3.disposables.Disposable) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NonNull(io.reactivex.rxjava3.annotations.NonNull) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 7 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class DeferredScalarObserverTest method disposedAfterOnNext.

@Test
public void disposedAfterOnNext() {
    final TestObserver<Integer> to = new TestObserver<>();
    TakeLast source = new TakeLast(new Observer<Integer>() {

        Disposable upstream;

        @Override
        public void onSubscribe(Disposable d) {
            this.upstream = d;
            to.onSubscribe(d);
        }

        @Override
        public void onNext(Integer value) {
            to.onNext(value);
            upstream.dispose();
        }

        @Override
        public void onError(Throwable e) {
            to.onError(e);
        }

        @Override
        public void onComplete() {
            to.onComplete();
        }
    });
    source.onSubscribe(Disposable.empty());
    source.onNext(1);
    source.onComplete();
    to.assertValue(1).assertNoErrors().assertNotComplete();
}
Also used : QueueDisposable(io.reactivex.rxjava3.operators.QueueDisposable) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 8 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class MaybeDoOnEventTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final Disposable bs = Disposable.empty();
        new Maybe<Integer>() {

            @Override
            protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(bs);
                observer.onError(new TestException("Second"));
                observer.onComplete();
                observer.onSuccess(1);
            }
        }.doOnSubscribe(new Consumer<Disposable>() {

            @Override
            public void accept(Disposable d) throws Exception {
                throw new TestException("First");
            }
        }).to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        assertTrue(bs.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 9 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class MaybeConcatArrayTest method errorAfterTermination.

@Test
public void errorAfterTermination() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final MaybeObserver<?>[] o = { null };
        Maybe.concatArrayDelayError(Maybe.just(1), Maybe.error(new IOException()), new Maybe<Integer>() {

            @Override
            protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onSuccess(2);
                o[0] = observer;
            }
        }).test().assertFailure(IOException.class, 1, 2);
        o[0].onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class MaybeDelayTest method delayedErrorOnError.

@Test
public void delayedErrorOnError() {
    final TestScheduler scheduler = new TestScheduler();
    final TestObserver<?> observer = Maybe.error(new TestException()).delay(5, TimeUnit.SECONDS, scheduler, true).test();
    scheduler.advanceTimeTo(2, TimeUnit.SECONDS);
    observer.assertNoErrors();
    scheduler.advanceTimeTo(5, TimeUnit.SECONDS);
    observer.assertError(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)139 TestException (io.reactivex.rxjava3.exceptions.TestException)88 InOrder (org.mockito.InOrder)75 Observable (io.reactivex.rxjava3.core.Observable)49 Disposable (io.reactivex.rxjava3.disposables.Disposable)49 TestObserver (io.reactivex.rxjava3.observers.TestObserver)37 IOException (java.io.IOException)29 Observer (io.reactivex.rxjava3.core.Observer)23 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)11 Function (io.reactivex.rxjava3.functions.Function)10 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)6 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)5 io.reactivex.rxjava3.subjects (io.reactivex.rxjava3.subjects)5 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5