void () { Alarm alarm = new Alarm(); StringBuilder sb = new StringBuilder(); Object modal = new Object(); LaterInvocator.enterModal(modal); try { ApplicationManager.getApplication().invokeLater(() -> TimeoutUtil.sleep(10), ModalityState.nonModal()); alarm.addRequest(() -> sb.append("1"), 0, ModalityState.nonModal()); alarm.addRequest(() -> sb.append("2"), 5, ModalityState.nonModal()); UIUtil.dispatchAllInvocationEvents(); assertEquals("", sb.toString()); } finally { LaterInvocator.leaveModal(modal); } while (!alarm.isEmpty()) { UIUtil.dispatchAllInvocationEvents(); } assertEquals("12", sb.toString()); }