Search in sources :

Example 6 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver 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 7 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class DeferredScalarObserverTest method dispose.

@Test
public void dispose() {
    TestObserver<Integer> to = new TestObserver<>();
    TakeFirst source = new TakeFirst(to);
    Disposable d = Disposable.empty();
    source.onSubscribe(d);
    assertFalse(d.isDisposed());
    to.dispose();
    assertTrue(d.isDisposed());
    assertTrue(source.isDisposed());
}
Also used : QueueDisposable(io.reactivex.rxjava3.operators.QueueDisposable) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 8 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class MaybeAmbTest method innerErrorRace.

@Test
public void innerErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp0 = PublishProcessor.create();
            final PublishProcessor<Integer> pp1 = PublishProcessor.create();
            final TestObserver<Integer> to = Maybe.amb(Arrays.asList(pp0.singleElement(), pp1.singleElement())).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp0.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    pp1.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            to.assertFailure(TestException.class);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 9 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.

the class MaybeDelaySubscriptionTest method timedTestScheduler.

@Test
public void timedTestScheduler() {
    TestScheduler scheduler = new TestScheduler();
    TestObserver<Integer> to = Maybe.just(1).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler).test();
    to.assertEmpty();
    scheduler.advanceTimeBy(99, TimeUnit.MILLISECONDS);
    to.assertEmpty();
    scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    to.assertResult(1);
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 10 with TestObserver

use of io.reactivex.rxjava3.observers.TestObserver 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)225 TestException (io.reactivex.rxjava3.exceptions.TestException)169 TestObserver (io.reactivex.rxjava3.observers.TestObserver)90 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)35 Disposable (io.reactivex.rxjava3.disposables.Disposable)34 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)27 TargetApi (android.annotation.TargetApi)21 Observable (io.reactivex.rxjava3.core.Observable)19 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)19 IOException (java.io.IOException)19 Matchers.anyString (org.mockito.Matchers.anyString)16 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)13 Action (io.reactivex.rxjava3.functions.Action)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 InOrder (org.mockito.InOrder)7 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)6 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)6 List (java.util.List)6 Assert (org.junit.Assert)6 Activity (android.app.Activity)5