Search in sources :

Example 1 with Functions

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

the class ObservableDematerializeTest method dematerialize3.

@Test
public void dematerialize3() {
    Exception exception = new Exception("test");
    Observable<Integer> o = Observable.error(exception);
    Observable<Integer> dematerialize = o.materialize().dematerialize(Functions.<Notification<Integer>>identity());
    Observer<Integer> observer = TestHelper.mockObserver();
    dematerialize.subscribe(observer);
    verify(observer, times(1)).onError(exception);
    verify(observer, times(0)).onComplete();
    verify(observer, times(0)).onNext(any(Integer.class));
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 2 with Functions

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

the class ObservableDematerializeTest method errorPassThru.

@Test
public void errorPassThru() {
    Exception exception = new Exception("test");
    Observable<Notification<Integer>> o = Observable.error(exception);
    Observable<Integer> dematerialize = o.dematerialize(Functions.<Notification<Integer>>identity());
    Observer<Integer> observer = TestHelper.mockObserver();
    dematerialize.subscribe(observer);
    verify(observer, times(1)).onError(exception);
    verify(observer, times(0)).onComplete();
    verify(observer, times(0)).onNext(any(Integer.class));
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 3 with Functions

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

the class ObservableGroupByTest method newGroupValueSelectorFails.

@Test
public void newGroupValueSelectorFails() {
    TestObserver<Object> to1 = new TestObserver<>();
    final TestObserver<Object> to2 = new TestObserver<>();
    Observable.just(1).groupBy(Functions.<Integer>identity(), new Function<Integer, Object>() {

        @Override
        public Object apply(Integer v) throws Throwable {
            throw new TestException();
        }
    }).doOnNext(new Consumer<GroupedObservable<Integer, Object>>() {

        @Override
        public void accept(GroupedObservable<Integer, Object> g) throws Throwable {
            g.subscribe(to2);
        }
    }).subscribe(to1);
    to1.assertValueCount(1).assertError(TestException.class).assertNotComplete();
    to2.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) GroupedObservable(io.reactivex.rxjava3.observables.GroupedObservable) Test(org.junit.Test)

Example 4 with Functions

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

the class TestObserverExTest method assertFailure.

@Test
public void assertFailure() {
    TestObserverEx<Integer> to = new TestObserverEx<>();
    to.onSubscribe(Disposable.empty());
    to.onError(new TestException("Forced failure"));
    to.assertFailure(TestException.class);
    to.assertFailure(Functions.<Throwable>alwaysTrue());
    to.assertFailureAndMessage(TestException.class, "Forced failure");
    to.onNext(1);
    to.assertFailure(TestException.class, 1);
    to.assertFailure(Functions.<Throwable>alwaysTrue(), 1);
    to.assertFailureAndMessage(TestException.class, "Forced failure", 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 5 with Functions

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

the class TestObserverExTest method assertError.

@Test
public void assertError() {
    TestObserverEx<Integer> to = new TestObserverEx<>();
    try {
        to.assertError(TestException.class);
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError ex) {
    // expected
    }
    try {
        to.assertError(new TestException());
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError ex) {
    // expected
    }
    try {
        to.assertError(Functions.<Throwable>alwaysTrue());
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError ex) {
    // expected
    }
    try {
        to.assertErrorMessage("");
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError exc) {
    // expected
    }
    try {
        to.assertSubscribed();
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError exc) {
    // expected
    }
    try {
        to.assertTerminated();
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError exc) {
    // expected
    }
    to.onSubscribe(Disposable.empty());
    to.assertSubscribed();
    to.assertNoErrors();
    TestException ex = new TestException("Forced failure");
    to.onError(ex);
    to.assertError(ex);
    to.assertError(TestException.class);
    to.assertError(Functions.<Throwable>alwaysTrue());
    to.assertError(new Predicate<Throwable>() {

        @Override
        public boolean test(Throwable t) throws Exception {
            return t.getMessage() != null && t.getMessage().contains("Forced");
        }
    });
    to.assertErrorMessage("Forced failure");
    try {
        to.assertErrorMessage("");
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError exc) {
    // expected
    }
    try {
        to.assertError(new RuntimeException());
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError exc) {
    // expected
    }
    try {
        to.assertError(IOException.class);
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError exc) {
    // expected
    }
    try {
        to.assertError(Functions.<Throwable>alwaysFalse());
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError exc) {
    // expected
    }
    try {
        to.assertNoErrors();
        throw new RuntimeException("Should have thrown");
    } catch (AssertionError exc) {
    // expected
    }
    to.assertTerminated();
    to.assertValueCount(0);
    to.assertNoValues();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) 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