void () { ApplicationManager.getApplication().invokeAndWait(() -> UITestUtil.runWithHeadlessProperty(false, () -> { myWindow1 = new Frame(); myWindow2 = new Frame(); JPanel panel = new JPanel(); myWindow1.add(panel); LaterInvocator.enterModal(myWindow1); ModalityState state1 = ModalityState.stateForComponent(myWindow1); assertSame(state1, ModalityState.stateForComponent(myWindow1)); assertSame(state1, ModalityState.stateForComponent(panel)); LaterInvocator.enterModal(myWindow1); assertSame(state1, ModalityState.stateForComponent(panel)); assertNotSame(state1, ModalityState.stateForComponent(myWindow2)); }) ); }