@Test
public void testRetrySuccess() {

    int NUM_RETRIES = 3;
    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 3 attempts
    inOrder.verify(observer, times(1 + NUM_FAILURES)).onNext("beginningEveryTime");
    // should have no errors
    inOrder.verify(observer, never()).onError(any(Throwable.class));
    // should have a single success
    inOrder.verify(observer, times(1)).onNext("onSuccessOnly");
    // should have a single successful onCompleted
    inOrder.verify(observer, times(1)).onCompleted();
    inOrder.verifyNoMoreInteractions();
}