Search in sources :

Example 31 with TestObserver

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

the class ObservableConcatWithMaybeTest method mainError.

@Test
public void mainError() {
    final TestObserver<Integer> to = new TestObserver<>();
    Observable.<Integer>error(new TestException()).concatWith(Maybe.<Integer>fromAction(new Action() {

        @Override
        public void run() throws Exception {
            to.onNext(100);
        }
    })).subscribe(to);
    to.assertFailure(TestException.class);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 32 with TestObserver

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

the class ObservableConcatWithCompletableTest method mainError.

@Test
public void mainError() {
    final TestObserver<Integer> to = new TestObserver<>();
    Observable.<Integer>error(new TestException()).concatWith(Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            to.onNext(100);
        }
    })).subscribe(to);
    to.assertFailure(TestException.class);
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 33 with TestObserver

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

the class ObservableConcatWithSingleTest method mainError.

@Test
public void mainError() {
    final TestObserver<Integer> to = new TestObserver<>();
    Observable.<Integer>error(new TestException()).concatWith(Single.just(100)).subscribe(to);
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 34 with TestObserver

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

the class ObservableCreateTest method serializedDrainDoneButNotEmpty.

@Test
public void serializedDrainDoneButNotEmpty() throws Throwable {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        TestObserver<Integer> to = new TestObserver<>();
        AtomicReference<ObservableEmitter<Integer>> ref = new AtomicReference<>();
        CountDownLatch cdl = new CountDownLatch(1);
        Observable.<Integer>create(emitter -> {
            emitter = emitter.serialize();
            ref.set(emitter);
            emitter.onNext(1);
        }).doOnNext(v -> {
            if (v == 1) {
                TestHelper.raceOther(() -> {
                    ref.get().onNext(2);
                    ref.get().onComplete();
                }, cdl);
                ref.get().onNext(3);
            }
        }).subscribe(to);
        cdl.await();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Cancellable(io.reactivex.rxjava3.functions.Cancellable) IOException(java.io.IOException) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Disposable(io.reactivex.rxjava3.disposables.Disposable) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) RxJavaPlugins(io.reactivex.rxjava3.plugins.RxJavaPlugins) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 35 with TestObserver

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

the class ObservableDelaySubscriptionOtherTest method noPrematureSubscription.

@Test
public void noPrematureSubscription() {
    PublishSubject<Object> other = PublishSubject.create();
    TestObserver<Integer> to = new TestObserver<>();
    final AtomicInteger subscribed = new AtomicInteger();
    Observable.just(1).doOnSubscribe(new Consumer<Disposable>() {

        @Override
        public void accept(Disposable d) {
            subscribed.getAndIncrement();
        }
    }).delaySubscription(other).subscribe(to);
    to.assertNotComplete();
    to.assertNoErrors();
    to.assertNoValues();
    Assert.assertEquals("Premature subscription", 0, subscribed.get());
    other.onNext(1);
    Assert.assertEquals("No subscription", 1, subscribed.get());
    to.assertValue(1);
    to.assertNoErrors();
    to.assertComplete();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposable(io.reactivex.rxjava3.disposables.Disposable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver)

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