Sequence { synchronized void set(final int index, final Runnable task) { tasks.set(index, task); if (index == next) { runEagerly(); } } Sequence(final int length);   }
@Test void runFirstEagerly() { unit.set(0, first); verify(first).run(); }
@Test void queuesSecond() { unit.set(1, second); verify(second, never()).run(); }
@Test void runsRestEagerly() { unit.set(2, third); unit.set(1, second); unit.set(0, first); final InOrder inOrder = inOrder(first, second, third); inOrder.verify(first).run(); inOrder.verify(second).run(); inOrder.verify(third).run(); }