@Override public void accept(Throwable v) throws Exception { onNotification.accept(Notification.<T>createOnError(v)); } }
@Override public void onError(Throwable e) { downstream.onSuccess(Notification.<T>createOnError(e)); }
@Override public void onError(Throwable t) { complete(Notification.<T>createOnError(t)); }
@Override public void accept(Throwable v) throws Exception { onNotification.accept(Notification.<T>createOnError(v)); } }
@Override public void onError(Throwable t) { Notification<T> v = Notification.createOnError(t); downstream.onNext(v); downstream.onComplete(); }
@Test public void testOnErrorIntegerNotificationsWhenEqual() { final Exception exception = new Exception(); final Notification<Integer> onErrorNotification = Notification.createOnError(exception); final Notification<Integer> onErrorNotification2 = Notification.createOnError(exception); Assert.assertTrue(onErrorNotification.equals(onErrorNotification2)); }
@Test public void testOnErrorIntegerNotificationWhenNotEqual() { final Notification<Integer> onErrorNotification = Notification.createOnError(new Exception()); final Notification<Integer> onErrorNotification2 = Notification.createOnError(new Exception()); Assert.assertFalse(onErrorNotification.equals(onErrorNotification2)); } }
@Test @Ignore("Nulls are not allowed") public void testOnErrorIntegerNotificationDoesNotEqualNullNotification() { final Notification<Integer> integerNotification = Notification.createOnError(new Exception()); final Notification<Integer> nullNotification = Notification.createOnError(null); Assert.assertFalse(integerNotification.equals(nullNotification)); }
@Test @Ignore("Nulls are not allowed") public void testOnErrorNullNotificationDoesNotEqualIntegerNotification() { final Notification<Integer> integerNotification = Notification.createOnError(new Exception()); final Notification<Integer> nullNotification = Notification.createOnError(null); Assert.assertFalse(nullNotification.equals(integerNotification)); }
@Override public boolean hasNext() { if (iteratorNotification != null && iteratorNotification.isOnError()) { throw ExceptionHelper.wrapOrThrow(iteratorNotification.getError()); } if (iteratorNotification == null) { try { BlockingHelper.verifyNonBlocking(); notify.acquire(); } catch (InterruptedException ex) { dispose(); iteratorNotification = Notification.createOnError(ex); throw ExceptionHelper.wrapOrThrow(ex); } Notification<T> n = value.getAndSet(null); iteratorNotification = n; if (n.isOnError()) { throw ExceptionHelper.wrapOrThrow(n.getError()); } } return iteratorNotification.isOnNext(); }
@Override public boolean hasNext() { if (iteratorNotification != null && iteratorNotification.isOnError()) { throw ExceptionHelper.wrapOrThrow(iteratorNotification.getError()); } if (iteratorNotification == null || iteratorNotification.isOnNext()) { if (iteratorNotification == null) { try { BlockingHelper.verifyNonBlocking(); notify.acquire(); } catch (InterruptedException ex) { dispose(); iteratorNotification = Notification.createOnError(ex); throw ExceptionHelper.wrapOrThrow(ex); } Notification<T> n = value.getAndSet(null); iteratorNotification = n; if (n.isOnError()) { throw ExceptionHelper.wrapOrThrow(n.getError()); } } } return iteratorNotification.isOnNext(); }
@Test public void valueOfOnErrorIsNull() { Notification<Integer> notification = Notification.createOnError(new TestException()); assertNull(notification.getValue()); assertTrue(notification.getError().toString(), notification.getError() instanceof TestException); }
@Test @SuppressWarnings("unchecked") public void error() { TestException ex = new TestException(); Maybe.error(ex) .materialize() .test() .assertResult(Notification.createOnError(ex)); }
@Test @SuppressWarnings("unchecked") public void error() { TestException ex = new TestException(); Completable.error(ex) .materialize() .test() .assertResult(Notification.createOnError(ex)); }
@Override protected void subscribeActual(Subscriber<? super Object> subscriber) { subscriber.onSubscribe(new BooleanSubscription()); subscriber.onNext(Notification.createOnComplete()); subscriber.onNext(Notification.createOnNext(1)); subscriber.onNext(Notification.createOnError(new TestException("First"))); subscriber.onError(new TestException("Second")); } }
@Test @SuppressWarnings("unchecked") public void error() { TestException ex = new TestException(); Maybe.error(ex) .materialize() .test() .assertResult(Notification.createOnError(ex)); }
@Test public void errorNotification() { Single.just(Notification.<Integer>createOnError(new TestException())) .dematerialize(Functions.<Notification<Integer>>identity()) .test() .assertFailure(TestException.class); }
@Test public void notEqualsToObject() { Notification<Integer> n1 = Notification.createOnNext(0); assertFalse(n1.equals(0)); Notification<Integer> n2 = Notification.createOnError(new TestException()); assertFalse(n2.equals(0)); Notification<Integer> n3 = Notification.createOnComplete(); assertFalse(n3.equals(0)); }
@Override protected void subscribeActual(Observer<? super Object> observer) { observer.onSubscribe(Disposables.empty()); observer.onNext(Notification.createOnComplete()); observer.onNext(Notification.createOnNext(1)); observer.onNext(Notification.createOnError(new TestException("First"))); observer.onError(new TestException("Second")); } }
@Test public void toStringPattern() { assertEquals("OnNextNotification[1]", Notification.createOnNext(1).toString()); assertEquals("OnErrorNotification[io.reactivex.exceptions.TestException]", Notification.createOnError(new TestException()).toString()); assertEquals("OnCompleteNotification", Notification.createOnComplete().toString()); } }