RetryWhenUnavailable implements RequestFeature { public Response process(RequestChain chain, Request request, String verb, URI uri, Object payload) { response = chain.next(request, verb, uri, payload); if(shouldRetry()) { response = chain.next(request, verb, uri, payload); } return response; }  Response process(RequestChain chain, Request request, String verb, URI uri, Object payload);  }
@Test public void shouldRetryWhenCode503() throws URISyntaxException { String verb = "get"; URI uri = new URI("http: when(chain.next(request, verb, uri, null)).thenReturn(response); when(response.getCode()).thenReturn(503); new RetryWhenUnavailable().process(chain, request, verb, uri, null); verify(chain, times(2)).next(request, verb, uri, null); }
@Test public void shouldNotRetryWhenUnkonwCode() throws URISyntaxException { String verb = "get"; URI uri = new URI("http: when(chain.next(request, verb, uri, null)).thenReturn(response); when(response.getCode()).thenReturn(200); new RetryWhenUnavailable().process(chain, request, verb, uri, null); verify(chain, times(1)).next(request, verb, uri, null); }