Search in sources :

Example 76 with TestObserver

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

the class CompletableAmbTest 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<Void> to = Completable.amb(Arrays.asList(pp0.ignoreElements(), pp1.ignoreElements())).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 77 with TestObserver

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

the class CompletableMergeTest method iterableCompleteLater.

@Test
public void iterableCompleteLater() {
    CompletableSubject cs = CompletableSubject.create();
    TestObserver<Void> to = Completable.mergeDelayError(Arrays.asList(cs, cs, cs)).test();
    to.assertEmpty();
    cs.onComplete();
    to.assertResult();
}
Also used : CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) Test(org.junit.Test)

Example 78 with TestObserver

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

the class CompletableTakeUntilTest method mainErrors.

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

Example 79 with TestObserver

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

the class CompletableAmbTest method ambRace.

@Test
public void ambRace() {
    TestObserver<Void> to = new TestObserver<>();
    to.onSubscribe(Disposable.empty());
    CompositeDisposable cd = new CompositeDisposable();
    AtomicBoolean once = new AtomicBoolean();
    Amb a = new Amb(once, cd, to);
    a.onSubscribe(Disposable.empty());
    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) Amb(io.reactivex.rxjava3.internal.operators.completable.CompletableAmb.Amb) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 80 with TestObserver

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

the class CompletableDelaySubscriptionTest method timestep.

@Test
public void timestep() {
    TestScheduler scheduler = new TestScheduler();
    final AtomicInteger counter = new AtomicInteger();
    Completable result = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            counter.incrementAndGet();
        }
    }).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
    TestObserver<Void> to = result.test();
    scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS);
    to.assertEmpty();
    scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
    to.assertResult();
    assertEquals(1, counter.get());
}
Also used : Action(io.reactivex.rxjava3.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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