Search in sources :

Example 6 with io.reactivex.rxjava3.functions

use of io.reactivex.rxjava3.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 7 with io.reactivex.rxjava3.functions

use of io.reactivex.rxjava3.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 8 with io.reactivex.rxjava3.functions

use of io.reactivex.rxjava3.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 9 with io.reactivex.rxjava3.functions

use of io.reactivex.rxjava3.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)

Example 10 with io.reactivex.rxjava3.functions

use of io.reactivex.rxjava3.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)

Aggregations

Test (org.junit.Test)30 TestException (io.reactivex.rxjava3.exceptions.TestException)24 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 IOException (java.io.IOException)6 Observable (io.reactivex.rxjava3.core.Observable)5 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)4 Maps (com.google.common.collect.Maps)2 String.format (java.lang.String.format)2 ByteBuffer (java.nio.ByteBuffer)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 java.util (java.util)2 TimeUnit (java.util.concurrent.TimeUnit)2 Pattern (java.util.regex.Pattern)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 Collectors.toSet (java.util.stream.Collectors.toSet)2 org.apache.cassandra.config (org.apache.cassandra.config)2 org.apache.cassandra.cql3 (org.apache.cassandra.cql3)2 QueryProcessor.executeInternal (org.apache.cassandra.cql3.QueryProcessor.executeInternal)2