@Test
public void testDelayWithError() {

    Observable<Long> source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).map(new Func1<Long, Long>() {
        @Override
        public Long call(Long value) {
            if (value == 1L) {
                throw new RuntimeException("error!");
            }
            return value;
        }
    });
    Observable<Long> delayed = source.delay(1L, TimeUnit.SECONDS, scheduler);
    delayed.subscribe(observer);
    InOrder inOrder = inOrder(observer);
    scheduler.advanceTimeTo(1999L, TimeUnit.MILLISECONDS);
    verify(observer, never()).onNext(anyLong());
    verify(observer, never()).onCompleted();
    verify(observer, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(2000L, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(1)).onError(any(Throwable.class));
    inOrder.verify(observer, never()).onNext(anyLong());
    verify(observer, never()).onCompleted();
    scheduler.advanceTimeTo(5000L, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, never()).onNext(anyLong());
    inOrder.verify(observer, never()).onError(any(Throwable.class));
    verify(observer, never()).onCompleted();
}