### Question:
ClientResumePolicies { public static <R, E> ClientResumePolicy<R, E> maxRepeat(final int maxRepeat) { return new ClientResumePolicy<R, E>() { @Override public Observable<HttpClientResponse<E>> onError(ServerClientContext<R, E> clientContext, int attempts, Throwable error) { return getNewResponse(clientContext, attempts); } @Override public Observable<HttpClientResponse<E>> onCompleted(ServerClientContext<R, E> clientContext, int attempts) { return getNewResponse(clientContext, attempts); } private Observable<HttpClientResponse<E>> getNewResponse(ServerClientContext<R, E> clientContext, int attempts) { if (attempts <= maxRepeat) { return clientContext.newResponse(); } return null; } }; }  static ClientResumePolicy<R, E> maxRepeat(final int maxRepeat); static ClientResumePolicy<R, E> noRepeat(); static ClientResumePolicy<R, E> delayed(final Func0<Long> delayFunc, final TimeUnit unit); static ClientResumePolicy<R, E> maxRepeat(final ClientResumePolicy<R, E> policy, final int maxRepeat);  }### Answer:
@Test public void testMaxRepeatOnCompletionAndError() throws Exception { int max = 10; ClientResumePolicy<String, String> policy = ClientResumePolicies.maxRepeat(max); ServerClientContext<String, String> context = new ServerClientContext<>(new ServerInfo("localhost", 1000), client, factory, observer); for (int i = 0; i < 20; ++i) { Observable<HttpClientResponse<String>> resumedOnCompleted = policy.onCompleted(context, i); Observable<HttpClientResponse<String>> resumedOnError = policy.onError(context, i, new Throwable("error")); if (i <= max) { assertNotNull(resumedOnCompleted); assertEquals(RESPONSE_CONTENT, resumedOnCompleted.toBlocking().first().getContent().toBlocking().first()); assertNotNull(resumedOnError); assertEquals(RESPONSE_CONTENT, resumedOnError.toBlocking().first().getContent().toBlocking().first()); } else { assertNull("The resumed on completion should be null as max repeat is passed", resumedOnCompleted); assertNull("The resumed on error should be null as max repeat is passed", resumedOnError); } } }