### Question:
AsyncRequest { public SettableFutureCallback<T> getCallback() { return callback; } AsyncRequest(
      AbstractGoogleJsonClientRequest<T> requestToExecute,
      RetryPolicy retryPolicy,
      OperationStats operationStats); void cancel(); AbstractGoogleJsonClientRequest<T> getRequest(); ListenableFuture<T> getFuture(); SettableFutureCallback<T> getCallback(); int getRetries(); void incrementRetries(); Status getStatus(); void setStatus(Status newStatus);  }### Answer:
@Test public void testOnStartWasNotPreviouslyCalled() throws IOException { AsyncRequest<GenericJson> req = new AsyncRequest<>(testRequest, retryPolicy, operationStats); thrown.expect(IllegalStateException.class); req.getCallback().onSuccess(new GenericJson(), new HttpHeaders()); }
@Test public void testSuccess() throws IOException { AsyncRequest<GenericJson> req = new AsyncRequest<>(testRequest, retryPolicy, operationStats); req.getCallback().onStart(); verify(operationStats).event(testRequest.getClass().getName()); verify(event, times(1)).start(); req.getCallback().onSuccess(new GenericJson(), new HttpHeaders()); verify(event, times(1)).success(); }
@Test public void testFailure() throws IOException { AsyncRequest<GenericJson> req = new AsyncRequest<>(testRequest, retryPolicy, operationStats); req.getCallback().onStart(); req.getCallback().onFailure(new GoogleJsonError(), new HttpHeaders()); req.getCallback().onFailure(new GoogleJsonError(), new HttpHeaders()); verify(operationStats, times(2)).event(testRequest.getClass().getName()); verify(event, times(1)).start(); verify(event, times(2)).failure(); }
@Test public void testRetryableFailure() throws IOException { AsyncRequest<GenericJson> req = new AsyncRequest<>(testRequest, retryPolicy, operationStats); when(retryPolicy.isRetryableStatusCode(anyInt())).thenReturn(true); req.getCallback().onStart(); req.getCallback().onFailure(new GoogleJsonError(), new HttpHeaders()); req.getCallback().onStart(); req.getCallback().onFailure(new GoogleJsonError(), new HttpHeaders()); req.getCallback().onStart(); req.getCallback().onSuccess(new GenericJson(), new HttpHeaders()); verify(operationStats, times(3)).event(testRequest.getClass().getName()); verify(event, times(3)).start(); verify(event, times(2)).failure(); verify(event, times(1)).success(); }
@Test public void testFailureUnstarted() throws IOException { AsyncRequest<GenericJson> req = new AsyncRequest<>(testRequest, retryPolicy, operationStats); req.getCallback().onFailure(new GoogleJsonError(), new HttpHeaders()); verify(operationStats).event(testRequest.getClass().getName()); verify(event, times(1)).failure(); }