Search in sources :

Example 11 with Observable

use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.

the class ObservableDebounceTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onComplete();
                observer.onNext(1);
                observer.onError(new TestException());
                observer.onComplete();
            }
        }.debounce(1, TimeUnit.SECONDS, new TestScheduler()).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler)

Example 12 with Observable

use of io.reactivex.rxjava3.core.Observable 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 13 with Observable

use of io.reactivex.rxjava3.core.Observable 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 14 with Observable

use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.

the class ObservableCreateTest method basicSerialized.

@Test
@SuppressUndeliverable
public void basicSerialized() {
    final Disposable d = Disposable.empty();
    Observable.<Integer>create(new ObservableOnSubscribe<Integer>() {

        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e = e.serialize();
            e.setDisposable(d);
            e.onNext(1);
            e.onNext(2);
            e.onNext(3);
            e.onComplete();
            e.onError(new TestException());
            e.onNext(4);
            e.onError(new TestException());
            e.onComplete();
        }
    }).test().assertResult(1, 2, 3);
    assertTrue(d.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Example 15 with Observable

use of io.reactivex.rxjava3.core.Observable in project RxJava by ReactiveX.

the class ObservableCreateTest method basicWithCancellable.

@Test
@SuppressUndeliverable
public void basicWithCancellable() {
    final Disposable d1 = Disposable.empty();
    final Disposable d2 = Disposable.empty();
    Observable.<Integer>create(new ObservableOnSubscribe<Integer>() {

        @Override
        public void subscribe(ObservableEmitter<Integer> e) throws Exception {
            e.setDisposable(d1);
            e.setCancellable(new Cancellable() {

                @Override
                public void cancel() throws Exception {
                    d2.dispose();
                }
            });
            e.onNext(1);
            e.onNext(2);
            e.onNext(3);
            e.onComplete();
            e.onError(new TestException());
            e.onNext(4);
            e.onError(new TestException());
            e.onComplete();
        }
    }).test().assertResult(1, 2, 3);
    assertTrue(d1.isDisposed());
    assertTrue(d2.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) Cancellable(io.reactivex.rxjava3.functions.Cancellable) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)132 TestException (io.reactivex.rxjava3.exceptions.TestException)109 Observable (io.reactivex.rxjava3.core.Observable)83 InOrder (org.mockito.InOrder)60 TestObserver (io.reactivex.rxjava3.observers.TestObserver)38 Disposable (io.reactivex.rxjava3.disposables.Disposable)35 IOException (java.io.IOException)25 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)22 Observer (io.reactivex.rxjava3.core.Observer)19 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)17 Function (io.reactivex.rxjava3.functions.Function)10 List (java.util.List)8 TimeUnit (java.util.concurrent.TimeUnit)8 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)7 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)6 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Collections (java.util.Collections)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Assert (org.junit.Assert)6