private void doTestSingleBucketVisit(VisitorParameters params,
                                         String expectedMessage)
    {
        MockSender sender = new MockSender();
        MockReceiver receiver = new MockReceiver();
        MockAsyncTaskExecutor executor = new MockAsyncTaskExecutor();

        MessageBusVisitorSession visitorSession = createVisitorSession(
                sender, receiver, executor, params);
        visitorSession.start();

        // Process initial task which sends a single CreateVisitor.
        executor.expectAndProcessTasks(1);
        assertEquals(expectedMessage, replyToCreateVisitor(sender, ProgressToken.FINISHED_BUCKET));
        assertFalse(visitorSession.isDone());

        // Single task for handling CreateVisitorReply.
        executor.expectAndProcessTasks(1);
        executor.expectNoTasks();
        assertTrue(visitorSession.isDone());
    }
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