void () { assert SwingUtilities.isEventDispatchThread(); IdeEventQueue ideEventQueue = IdeEventQueue.getInstance(); CompletableFuture<Object> future = new CompletableFuture<>(); TestTimeOut cancelEventTime = TestTimeOut.setTimeout(2, TimeUnit.SECONDS); JLabel component = new JLabel(); long start = System.currentTimeMillis(); ideEventQueue.pumpEventsForHierarchy(component, future, __ -> { if (cancelEventTime.isTimedOut()) { future.complete(null); } // post InvocationEvent to give getNextEvent work to do SwingUtilities.invokeLater(EmptyRunnable.getInstance()); }); long elapsedMs = System.currentTimeMillis() - start; // check that first, we did exit the pumpEventsForHierarchy and second, at the right moment assertTrue(String.valueOf(elapsedMs), cancelEventTime.isTimedOut()); }