void () { UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { final ArrayList<String> consumed = new ArrayList<>(); synchronized (LaterInvocatorTest.this) { blockSwingThread(); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { ApplicationManager.getApplication().invokeLater(new MyRunnable("1") { @Override public void run() { super.run(); TestCase.fail("Should not be executed"); } }, Conditions.alwaysTrue()); consumed.add("1"); } }, ModalityState.nonModal()); ApplicationManager.getApplication().invokeLater(() -> { new MyRunnable("2").run(); consumed.add("2"); }, ModalityState.nonModal()); } flushSwingQueue(); TestCase.assertEquals(consumed.toString(), 2, consumed.size()); } }); }