Search in sources :

Example 1 with OnErrorNotImplementedException

use of rx.exceptions.OnErrorNotImplementedException in project storio by pushtorefresh.

the class AbstractEmissionCheckerTest method shouldThrowExcepionBecauseObservableEmittedUnexpectedItemAfterExpectedSequence.

@Test
public void shouldThrowExcepionBecauseObservableEmittedUnexpectedItemAfterExpectedSequence() {
    final Queue<String> expectedValues = new LinkedList<String>();
    expectedValues.add("1");
    expectedValues.add("2");
    expectedValues.add("3");
    final PublishSubject<String> publishSubject = PublishSubject.create();
    final AbstractEmissionChecker<String> emissionChecker = new AbstractEmissionChecker<String>(expectedValues) {

        @NonNull
        @Override
        public Subscription subscribe() {
            return publishSubject.subscribe(new Action1<String>() {

                @Override
                public void call(String s) {
                    onNextObtained(s);
                }
            });
        }
    };
    final Subscription subscription = emissionChecker.subscribe();
    publishSubject.onNext("1");
    publishSubject.onNext("2");
    publishSubject.onNext("3");
    emissionChecker.awaitNextExpectedValue();
    emissionChecker.awaitNextExpectedValue();
    emissionChecker.awaitNextExpectedValue();
    emissionChecker.assertThatNoExpectedValuesLeft();
    try {
        publishSubject.onNext("4");
        failBecauseExceptionWasNotThrown(OnErrorNotImplementedException.class);
    } catch (OnErrorNotImplementedException expected) {
        assertThat(expected.getCause()).hasMessage("Received emission, but no more emissions were expected: obtained 4, expectedValues = [], obtainedValues = []");
    } finally {
        subscription.unsubscribe();
    }
}
Also used : OnErrorNotImplementedException(rx.exceptions.OnErrorNotImplementedException) Subscription(rx.Subscription) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with OnErrorNotImplementedException

use of rx.exceptions.OnErrorNotImplementedException in project retrofit by square.

the class CallArbiter method deliverResponse.

private void deliverResponse(Response<T> response) {
    try {
        if (!isUnsubscribed()) {
            subscriber.onNext(response);
        }
    } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) {
        RxJavaPlugins.getInstance().getErrorHandler().handleError(e);
        return;
    } catch (Throwable t) {
        Exceptions.throwIfFatal(t);
        try {
            subscriber.onError(t);
        } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) {
            RxJavaPlugins.getInstance().getErrorHandler().handleError(e);
        } catch (Throwable inner) {
            Exceptions.throwIfFatal(inner);
            CompositeException composite = new CompositeException(t, inner);
            RxJavaPlugins.getInstance().getErrorHandler().handleError(composite);
        }
        return;
    }
    try {
        if (!isUnsubscribed()) {
            subscriber.onCompleted();
        }
    } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) {
        RxJavaPlugins.getInstance().getErrorHandler().handleError(e);
    } catch (Throwable t) {
        Exceptions.throwIfFatal(t);
        RxJavaPlugins.getInstance().getErrorHandler().handleError(t);
    }
}
Also used : OnCompletedFailedException(rx.exceptions.OnCompletedFailedException) CompositeException(rx.exceptions.CompositeException) OnErrorNotImplementedException(rx.exceptions.OnErrorNotImplementedException) OnErrorFailedException(rx.exceptions.OnErrorFailedException)

Aggregations

OnErrorNotImplementedException (rx.exceptions.OnErrorNotImplementedException)2 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1 Subscription (rx.Subscription)1 CompositeException (rx.exceptions.CompositeException)1 OnCompletedFailedException (rx.exceptions.OnCompletedFailedException)1 OnErrorFailedException (rx.exceptions.OnErrorFailedException)1