void () { //happens with per-project modality Object modal1 = ObjectUtils.sentinel("modal1"); Object modal2 = ObjectUtils.sentinel("modal2"); UIUtil.invokeAndWaitIfNeeded(() -> { LaterInvocator.enterModal(modal1); // [modal1] ModalityState ms_1 = ModalityState.current(); ApplicationManager.getApplication().invokeLater(new MyRunnable("m1"), ms_1); LaterInvocator.enterModal(modal2); //[modal1, modal2] ModalityState ms_12 = ModalityState.current(); assertNotSame(ms_1, ms_12); assertTrue(ms_12.dominates(ms_1)); UIUtil.dispatchAllInvocationEvents(); assertEmpty(myOrder); ApplicationManager.getApplication().invokeLater(new MyRunnable("m12"), ms_12); LaterInvocator.leaveModal(modal1); // [modal2] assertEmpty(myOrder); UIUtil.dispatchAllInvocationEvents(); assertOrderedEquals(myOrder, "m12"); ModalityState ms_2 = ModalityState.current(); assertSame(ms_12, ms_2); assertTrue(ms_2.dominates(ms_1)); ApplicationManager.getApplication().invokeLater(new MyRunnable("m1x"), ms_1); ApplicationManager.getApplication().invokeLater(new MyRunnable("m2"), ms_2); UIUtil.dispatchAllInvocationEvents(); assertOrderedEquals(myOrder, "m12", "m2"); LaterInvocator.leaveModal(modal2); // NON_MODAL UIUtil.dispatchAllInvocationEvents(); assertOrderedEquals(myOrder, "m12", "m2", "m1", "m1x"); }); }