@Test
public void testRetryFail() {

    int NUM_RETRIES = 1;
    int NUM_FAILURES = 2;
    @SuppressWarnings("unchecked")
    Observer<String> observer = mock(Observer.class);
    Observable<String> origin = Observable.create(new FuncWithErrors(NUM_FAILURES));
    Observable.create(retry(origin, NUM_RETRIES)).subscribe(observer);
    InOrder inOrder = inOrder(observer);
    // should show 2 attempts (first time fail, second time (1st retry) fail)
    inOrder.verify(observer, times(1 + NUM_RETRIES)).onNext("beginningEveryTime");
    // should only retry once, fail again and emit onError
    inOrder.verify(observer, times(1)).onError(any(RuntimeException.class));
    // no success
    inOrder.verify(observer, never()).onNext("onSuccessOnly");
    inOrder.verify(observer, never()).onCompleted();
    inOrder.verifyNoMoreInteractions();
}