Search in sources :

Example 6 with Functions

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

the class TestObserverExTest method assertErrorMultiple.

@Test
public void assertErrorMultiple() {
    TestObserverEx<Integer> to = new TestObserverEx<>();
    TestException e = new TestException();
    to.errors().add(e);
    to.errors().add(new TestException());
    try {
        to.assertError(TestException.class);
        throw new RuntimeException("Should have thrown!");
    } catch (AssertionError ex) {
    // expected
    }
    try {
        to.assertError(e);
        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 ex) {
    // expected
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 7 with Functions

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

the class FlowableSubscriberTest method doubleSubscribe.

@Test
public void doubleSubscribe() {
    ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) throws Exception {
            return true;
        }
    }, Functions.<Throwable>emptyConsumer(), Functions.EMPTY_ACTION);
    List<Throwable> list = TestHelper.trackPluginErrors();
    try {
        s.onSubscribe(new BooleanSubscription());
        BooleanSubscription bs = new BooleanSubscription();
        s.onSubscribe(bs);
        assertTrue(bs.isCancelled());
        TestHelper.assertError(list, 0, IllegalStateException.class, "Subscription already set!");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : ForEachWhileSubscriber(io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 8 with Functions

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

the class ParallelSortedJoinTest method error3.

@Test
public void error3() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.<Integer>error(new TestException()).parallel().sorted(Functions.<Integer>naturalComparator()).test(0).assertFailure(TestException.class);
        assertTrue(errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 9 with Functions

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

the class ParallelSortedJoinTest method error.

@Test
public void error() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.<Integer>error(new TestException()).parallel().sorted(Functions.<Integer>naturalComparator()).test().assertFailure(TestException.class);
        assertTrue(errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 10 with Functions

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

the class TestObserverTest method assertError.

@Test
public void assertError() {
    TestObserver<Integer> to = TestObserver.create();
    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.assertSubscribed();
        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");
        }
    });
    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.assertValueCount(0);
    to.assertNoValues();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) IOException(java.io.IOException) 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