public void expectAndProcessTasks(int expectedTaskCount,
                                          int processCount,
                                          long[] taskRunAtTime)
        {
            if (tasks.size() != expectedTaskCount) {
                throw new IllegalStateException("Expected " + expectedTaskCount +
                        " queued tasks, found " + tasks.size());
            }
            if (taskRunAtTime != null && taskRunAtTime.length != tasks.size()) {
                throw new IllegalStateException("Task time array must be equal in size to number of tasks");
            }
            for (int i = 0; i < processCount; ++i) {
                Iterator<TaskDescriptor> iter = tasks.iterator();
                TaskDescriptor td = iter.next();
                if (taskRunAtTime != null) {
                    if (taskRunAtTime[i] != td.getTimestamp()) {
                        throw new IllegalStateException(
                                "Expected task with scheduled execution time " +
                                taskRunAtTime[i] + ", was " + td.getTimestamp());
                    }
                }
                iter.remove();
                td.getTask().run();
            }
        }
Mock the executor to keep things nicely single threaded for the testing.
No need to synchronize things here since we don't use multiple threads.
documentapi/src/test/java/com/yahoo/documentapi/messagebus/MessageBusVisitorSessionTestCase.java