Search in sources :

Example 51 with TestObserver

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

the class SerializedSubjectTest method onNextOnSubscribeRace.

@Test
public void onNextOnSubscribeRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
        TestObserver<Integer> to = s.test();
        final Disposable bs = Disposable.empty();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                s.onNext(1);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                s.onSubscribe(bs);
            }
        };
        TestHelper.race(r1, r2);
        to.assertValue(1).assertNotComplete().assertNoErrors();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 52 with TestObserver

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

the class SerializedSubjectTest method onCompleteOnSubscribeRace.

@Test
public void onCompleteOnSubscribeRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
        TestObserver<Integer> to = s.test();
        final Disposable bs = Disposable.empty();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                s.onComplete();
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                s.onSubscribe(bs);
            }
        };
        TestHelper.race(r1, r2);
        to.assertResult();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 53 with TestObserver

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

the class SerializedSubjectTest method normal.

@Test
public void normal() {
    Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    Observable.range(1, 10).subscribe(s);
    to.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    assertFalse(s.hasObservers());
    s.onNext(11);
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        s.onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
    s.onComplete();
    Disposable bs = Disposable.empty();
    s.onSubscribe(bs);
    assertTrue(bs.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 54 with TestObserver

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

the class XFlatMapTest method flowableCompletable.

@Test
public void flowableCompletable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Void> to = Flowable.just(1).subscribeOn(Schedulers.io()).flatMapCompletable(new Function<Integer, Completable>() {

            @Override
            public Completable apply(Integer v) throws Exception {
                sleep();
                return Completable.error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 55 with TestObserver

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

the class XFlatMapTest method maybeObservable.

@Test
public void maybeObservable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Maybe.just(1).subscribeOn(Schedulers.io()).flatMapObservable(new Function<Integer, Observable<Integer>>() {

            @Override
            public Observable<Integer> apply(Integer v) throws Exception {
                sleep();
                return Observable.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

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