Search in sources :

Example 21 with Functions

use of io.reactivex.rxjava3.internal.functions.Functions in project RxJava by ReactiveX.

the class FlowableDematerializeTest method eventsAfterDematerializedTerminal.

@Test
public void eventsAfterDematerializedTerminal() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Flowable<Notification<Object>>() {

            @Override
            protected void subscribeActual(Subscriber<? super Notification<Object>> subscriber) {
                subscriber.onSubscribe(new BooleanSubscription());
                subscriber.onNext(Notification.createOnComplete());
                subscriber.onNext(Notification.<Object>createOnNext(1));
                subscriber.onNext(Notification.createOnError(new TestException("First")));
                subscriber.onError(new TestException("Second"));
            }
        }.dematerialize(Functions.<Notification<Object>>identity()).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 1, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 22 with Functions

use of io.reactivex.rxjava3.internal.functions.Functions in project RxJava by ReactiveX.

the class ObservableWindowWithStartEndObservableTest method startError.

@Test
public void startError() {
    PublishSubject<Integer> source = PublishSubject.create();
    PublishSubject<Integer> start = PublishSubject.create();
    final PublishSubject<Integer> end = PublishSubject.create();
    TestObserver<Integer> to = source.window(start, new Function<Integer, ObservableSource<Integer>>() {

        @Override
        public ObservableSource<Integer> apply(Integer v) throws Exception {
            return end;
        }
    }).flatMap(Functions.<Observable<Integer>>identity()).test();
    start.onError(new TestException());
    to.assertFailure(TestException.class);
    assertFalse("Source has observers!", source.hasObservers());
    assertFalse("Start has observers!", start.hasObservers());
    assertFalse("End has observers!", end.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) Observable(io.reactivex.rxjava3.core.Observable)

Example 23 with Functions

use of io.reactivex.rxjava3.internal.functions.Functions in project RxJava by ReactiveX.

the class ObservableWindowWithTimeTest method exactOnError.

@Test
@SuppressUndeliverable
public void exactOnError() {
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<Integer> ps = PublishSubject.create();
    TestObserver<Integer> to = ps.window(1, 1, TimeUnit.SECONDS, scheduler).flatMap(Functions.<Observable<Integer>>identity()).test();
    ps.onError(new TestException());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Observable(io.reactivex.rxjava3.core.Observable)

Example 24 with Functions

use of io.reactivex.rxjava3.internal.functions.Functions in project RxJava by ReactiveX.

the class LambdaObserverTest method disposedObserverShouldReportErrorOnGlobalErrorHandler.

@Test
public void disposedObserverShouldReportErrorOnGlobalErrorHandler() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final List<Throwable> observerErrors = Collections.synchronizedList(new ArrayList<>());
        LambdaObserver<Integer> o = new LambdaObserver<>(Functions.<Integer>emptyConsumer(), new Consumer<Throwable>() {

            @Override
            public void accept(Throwable t) {
                observerErrors.add(t);
            }
        }, Functions.EMPTY_ACTION, Functions.<Disposable>emptyConsumer());
        o.dispose();
        o.onError(new IOException());
        o.onError(new IOException());
        assertTrue(observerErrors.isEmpty());
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
        TestHelper.assertUndeliverable(errors, 1, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : IOException(java.io.IOException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 25 with Functions

use of io.reactivex.rxjava3.internal.functions.Functions in project RxJava by ReactiveX.

the class ObservableDematerializeTest method honorsContractWhenThrows.

@Test
public void honorsContractWhenThrows() {
    Observable<Integer> source = Observable.error(new TestException());
    Observable<Integer> result = source.materialize().dematerialize(Functions.<Notification<Integer>>identity());
    Observer<Integer> o = TestHelper.mockObserver();
    result.subscribe(o);
    verify(o, never()).onNext(any(Integer.class));
    verify(o, never()).onComplete();
    verify(o).onError(any(TestException.class));
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)22 Test (org.junit.Test)22 IOException (java.io.IOException)6 Observable (io.reactivex.rxjava3.core.Observable)5 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)4 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)4 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)1 GroupedObservable (io.reactivex.rxjava3.observables.GroupedObservable)1