VotingFuture extends AbstractFuture<T> { void voteYes() { if (castVote()) { synchronized (failures) { resolveResult(); } } } VotingFuture(final T result, final int requiredVotes);   }
@Test public void testVoteYes() throws Exception { future.voteYes(); future.voteYes(); future.voteYes(); assertFutureEquals(result, future); }
@Test public void testVoteYesBlocking() throws Exception { final AtomicBoolean voted = new AtomicBoolean(false); future.voteYes(); future.voteYes(); executor.schedule(() -> { voted.set(true); future.voteYes(); }, 1, TimeUnit.SECONDS); assertFutureEquals(result, future); Assert.assertTrue("Future completed before vote", voted.get()); }