I.E: something like this:

   private void checkFlushHierarchy(
        List<ILoggingEvent> loggedEvents,
        boolean affected,
        Runnable flusher,
        Runnable command)
    {
        // Run command for first time.
        command.run();

        // Now cache is primed, running the command for second time should not
        // require any additional SQL. (There is a small chance that GC will
        // kick in and we'll lose the cache, but we've never seen that happen
        // in the wild.)
        loggedEvents.clear();
        command.run();
        assertEquals(0, loggedEvents.size());
        flusher.run();

        // Now cache has been flushed, it should be impossible to execute the
        // command without running additional SQL.
        command.run();
        if (affected) {
            assertNotSame(0, loggedEvents.size());
        }
    }