### Question:
Requests { public static LiveHttpRequest doOnComplete(LiveHttpRequest request, Runnable action) { return request.newBuilder() .body(it -> it.doOnEnd(ifSuccessful(action))) .build(); } private  Requests(); static LiveHttpRequest doFinally(LiveHttpRequest request, Consumer<Optional<Throwable>> action); static LiveHttpResponse doFinally(LiveHttpResponse response, Consumer<Optional<Throwable>> action); static LiveHttpRequest doOnComplete(LiveHttpRequest request, Runnable action); static LiveHttpResponse doOnComplete(LiveHttpResponse response, Runnable action); static LiveHttpRequest doOnError(LiveHttpRequest request, Consumer<Throwable> action); static LiveHttpResponse doOnError(LiveHttpResponse response, Consumer<Throwable> action); static LiveHttpRequest doOnCancel(LiveHttpRequest request, Runnable action); static LiveHttpResponse doOnCancel(LiveHttpResponse response, Runnable action);  }### Answer:
@Test public void requestDoOnCompleteActivatesWhenSuccessfullyCompleted() { Requests.doOnComplete(request, () -> completed.set(Optional.empty())) .consume(); publisher.next(new Buffer("content", UTF_8)); assertThat(completed.get(), is(nullValue())); publisher.complete(); assertThat(completed.get(), is(Optional.empty())); }
@Test public void responseDoOnCompleteActivatesWhenSuccessfullyCompleted() { Requests.doOnComplete(response, () -> completed.set(Optional.empty())) .consume(); publisher.next(new Buffer("content", UTF_8)); assertThat(completed.get(), is(nullValue())); publisher.complete(); assertThat(completed.get(), is(Optional.empty())); }
@Test public void requestDoOnCompleteDoesNotActivatesWhenErrors() { RuntimeException cause = new RuntimeException("help!!"); Requests.doOnComplete(request, () -> completed.set(Optional.empty())) .consume(); publisher.next(new Buffer("content", UTF_8)); assertThat(completed.get(), is(nullValue())); publisher.error(cause); assertThat(completed.get(), is(nullValue())); }
@Test public void responseDoOnCompleteDoesNotActivatesWhenErrors() { RuntimeException cause = new RuntimeException("help!!"); Requests.doOnComplete(response, () -> completed.set(Optional.empty())) .consume(); publisher.next(new Buffer("content", UTF_8)); assertThat(completed.get(), is(nullValue())); publisher.error(cause); assertThat(completed.get(), is(nullValue())); }