Search in sources :

Example 71 with TestObserver

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

the class TestObserverTest method errorInPredicate.

@Test
public void errorInPredicate() {
    TestObserver<Object> to = new TestObserver<>();
    to.onError(new RuntimeException());
    try {
        to.assertError(new Predicate<Throwable>() {

            @Override
            public boolean test(Throwable throwable) throws Exception {
                throw new TestException();
            }
        });
    } catch (TestException ex) {
        // expected
        return;
    }
    fail("Error in predicate but not thrown!");
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 72 with TestObserver

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

the class SerializedObserverTest method onNextOnErrorRace.

@Test
public void onNextOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        TestObserver<Integer> to = new TestObserver<>();
        final SerializedObserver<Integer> so = new SerializedObserver<>(to);
        Disposable d = Disposable.empty();
        so.onSubscribe(d);
        final Throwable ex = new TestException();
        Runnable r1 = new Runnable() {

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

            @Override
            public void run() {
                so.onNext(1);
            }
        };
        TestHelper.race(r1, r2);
        to.awaitDone(5, TimeUnit.SECONDS).assertError(ex).assertNotComplete();
        assertTrue(to.values().size() <= 1);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 73 with TestObserver

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

the class CompletableSwitchOnNextTest method delaySwitch.

@Test
public void delaySwitch() {
    PublishProcessor<Completable> pp = PublishProcessor.create();
    TestObserver<Void> to = Completable.switchOnNextDelayError(pp).test();
    assertTrue(pp.hasSubscribers());
    to.assertEmpty();
    CompletableSubject cs1 = CompletableSubject.create();
    CompletableSubject cs2 = CompletableSubject.create();
    pp.onNext(cs1);
    assertTrue(cs1.hasObservers());
    pp.onNext(cs2);
    assertFalse(cs1.hasObservers());
    assertTrue(cs2.hasObservers());
    assertTrue(cs2.hasObservers());
    cs2.onError(new TestException());
    assertTrue(pp.hasSubscribers());
    to.assertEmpty();
    pp.onComplete();
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) Test(org.junit.Test)

Example 74 with TestObserver

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

the class CompletableTimeoutTest method ambRace.

@Test
public void ambRace() {
    TestObserver<Void> to = new TestObserver<>();
    to.onSubscribe(Disposable.empty());
    CompositeDisposable cd = new CompositeDisposable();
    AtomicBoolean once = new AtomicBoolean();
    TimeOutObserver a = new TimeOutObserver(cd, once, to);
    a.onComplete();
    a.onComplete();
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        a.onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestException(io.reactivex.rxjava3.exceptions.TestException) TimeOutObserver(io.reactivex.rxjava3.internal.operators.completable.CompletableTimeout.TimeOutObserver) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 75 with TestObserver

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

the class CompletableAmbTest method untilCompletableOtherError.

@Test
public void untilCompletableOtherError() {
    CompletableSubject main = CompletableSubject.create();
    CompletableSubject other = CompletableSubject.create();
    TestObserver<Void> to = main.ambWith(other).test();
    assertTrue("Main no observers?", main.hasObservers());
    assertTrue("Other no observers?", other.hasObservers());
    other.onError(new TestException());
    assertFalse("Main has observers?", main.hasObservers());
    assertFalse("Other has observers?", other.hasObservers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) 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