BulkMutationGCJClient implements IBulkMutation { @Override public void flush() { try { bulkMutateBatcher.flush(); } catch (InterruptedException ex) { throw new RuntimeException("Could not complete RPC for current Batch", ex); } } BulkMutationGCJClient(Batcher<RowMutationEntry, Void> bulkMutateBatcher); @Override synchronized ApiFuture<Void> add(RowMutationEntry rowMutation); @Override void sendUnsent(); @Override void flush(); @Override void close();  }
@Test public void testFlush() throws Exception { final SettableApiFuture<Void> future = SettableApiFuture.create(); final SettableApiFuture<Void> future2 = SettableApiFuture.create(); when(batcher.add(rowMutation)).thenReturn(future).thenReturn(future2); doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocationOnMock) { future.set(null); future2.set(null); return null; } }) .when(batcher) .flush(); ApiFuture<Void> result1 = bulkMutationClient.add(rowMutation); ApiFuture<Void> result2 = bulkMutationClient.add(rowMutation); bulkMutationClient.flush(); assertTrue(result1.isDone()); assertTrue(result2.isDone()); verify(batcher, times(2)).add(rowMutation); verify(batcher).flush(); }