@SuppressWarnings("unchecked")
@Test
public void testAutoflush() throws Exception {

  // Setup a BulkMutation with autoflush enabled: the scheduled flusher will get captured by the
  // scheduled executor mock
  underTest =
      new BulkMutation(
          TABLE_NAME,
          client,
          operationAccountant,
          retryExecutorService,
          BulkOptions.builder().setAutoflushMs(1000L).build());
  ArgumentCaptor<Runnable> autoflusher = ArgumentCaptor.forClass(Runnable.class);
  when(retryExecutorService.schedule(autoflusher.capture(), anyLong(), any(TimeUnit.class)))
      .thenReturn(mockScheduledFuture);
  // buffer a request, with a mocked success (for never it gets invoked)
  underTest.add(createRequestEntry());
  // Verify that the autoflusher was scheduled
  verify(retryExecutorService, times(1))
      .schedule(autoflusher.capture(), anyLong(), any(TimeUnit.class));
  // Verify that the request wasn't sent
  verify(client, never()).mutateRowsAsync(any(MutateRowsRequest.class));
  // Fake the triggering of the autoflusher
  autoflusher.getValue().run();
  // Verify that the request was sent
  verify(client, times(1)).mutateRowsAsync(any(MutateRowsRequest.class));
}