### Question:
BatchRequestService extends AbstractIdleService { public ListenableFuture<Integer> flush() throws InterruptedException { return flush(false); } BatchRequestService(Builder builder); void add(AsyncRequest<T> request); int getCurrentBatchSize(); ListenableFuture<Integer> flush();  }### Answer:
@Test public void testFlush() throws Exception { BatchRequestService batchService = setupService(); batchService.startAsync().awaitRunning(); assertTrue(batchService.isRunning()); BatchRequest batchRequest = getMockBatchRequest(); when(batchRequestHelper.createBatch(any())).thenReturn(batchRequest); AsyncRequest<GenericJson> requestToBatch = new AsyncRequest<GenericJson>(testRequest, retryPolicy, operationStats); doAnswer( invocation -> { requestToBatch.getCallback().onStart(); requestToBatch.getCallback().onSuccess(new GenericJson(), new HttpHeaders()); return null; }) .when(batchRequestHelper) .executeBatchRequest(batchRequest); batchService.add(requestToBatch); batchService.flush(); batchService.stopAsync().awaitTerminated(); assertEquals(new GenericJson(), requestToBatch.getFuture().get()); assertFalse(batchService.isRunning()); }
@Test public void testGenericJsonFlush() throws Exception { BatchRequestService batchService = setupService(); batchService.startAsync().awaitRunning(); assertTrue(batchService.isRunning()); batchService.flush(); batchService.stopAsync().awaitTerminated(); assertFalse(batchService.isRunning()); verifyNoMoreInteractions(batchRequestHelper); }