### Question:
ApolloExecutor { public <D extends Data, T, V extends Variables> CompletableFuture<Response<T>> execute(Mutation<D, T, V> mutation) { var future = new CompletableFuture<Response<T>>(); client.mutate(mutation).enqueue(new Callback<>(future)); return future; }  CompletableFuture<Response<T>> execute(Mutation<D, T, V> mutation); CompletableFuture<Response<T>> execute(Query<D, T, V> query);  }### Answer:
@Test public void onResponseNoErrors() { when(client.mutate(mutation)).thenReturn(mutationCall); var result = underTest.execute(mutation); var captor = ArgumentCaptor.forClass(Callback.class); verify(client).mutate(mutation); verify(mutationCall).enqueue(captor.capture()); var callback = captor.getValue(); assertThat(result.isDone(), is(false)); when(response.hasErrors()).thenReturn(false); callback.onResponse(response); assertThat(result.isDone(), is(true)); }
@Test public void onResponseErrors() { when(client.mutate(mutation)).thenReturn(mutationCall); var result = underTest.execute(mutation); var captor = ArgumentCaptor.forClass(Callback.class); verify(client).mutate(mutation); verify(mutationCall).enqueue(captor.capture()); var callback = captor.getValue(); assertThat(result.isDone(), is(false)); when(response.hasErrors()).thenReturn(true); callback.onResponse(response); assertThat(result.isCompletedExceptionally(), is(true)); }
@Test public void onFailure() { when(client.mutate(mutation)).thenReturn(mutationCall); var result = underTest.execute(mutation); var captor = ArgumentCaptor.forClass(Callback.class); verify(client).mutate(mutation); verify(mutationCall).enqueue(captor.capture()); Callback callback = captor.getValue(); assertThat(result.isDone(), is(false)); callback.onFailure(new ApolloException("")); assertThat(result.isCompletedExceptionally(), is(true)); }