void () { UIUtil.invokeAndWaitIfNeeded(() -> { int N = 1000; for (int i = 0; i < N; i++) { UsefulTestCase.assertEmpty(LaterInvocator.getCurrentModalEntities()); LaterInvocator.enterModal(myWindow2); //some weird things like MyFireIdleRequest may still sneak in //assertEquals(null, LaterInvocator.dumpQueue()); TestCase.assertTrue(LaterInvocator.isInModalContext()); TestCase.assertEquals(1, LaterInvocator.getCurrentModalEntities().length); LaterInvocator.invokeLater(ModalityState.nonModal(), Conditions.alwaysFalse(), new Runnable() { @Override public void run() { assertFalse(LaterInvocator.isInModalContext()); } public String toString() { return "ass2"; } }); LaterInvocator.invokeLater(ModalityState.nonModal(), Conditions.alwaysFalse(), ENTER_MODAL); LaterInvocator.invokeLater(ModalityState.nonModal(), Conditions.alwaysFalse(), new MyRunnable("1")); //some weird things like MyFireIdleRequest may still sneak in //java.util.List<Object> dump = LaterInvocator.dumpQueue(); //assertEquals(dump.toString(), 3, dump.size()); LaterInvocator.leaveModal(myWindow2); flushSwingQueue(); assertTrue(LaterInvocator.isInModalContext()); checkOrder(0); SwingUtilities.invokeLater(LEAVE_MODAL); flushSwingQueue(); assertFalse(LaterInvocator.isInModalContext()); checkOrder(1); LaterInvocator.leaveAllModals(); myOrder.clear(); flushSwingQueue(); } }); }