*
* @throws Error if no popup is shown before the timeout expires.
*/
public static MenuItem run(final Trigger trigger) {
PopupHandler interceptor = new PopupHandler();
final UISpecDisplay display = UISpecDisplay.instance();
try {
display.add(interceptor);
display.setCurrentPopup(null);
TriggerRunner.runInSwingThread(trigger);
UISpecAssert.waitUntil("No popup was shown",
new Assertion() {
public void check() {
if (display.getCurrentPopup() == null) {
AssertAdapter.fail("No popup shown");
}
;
}
},
UISpec4J.getWindowInterceptionTimeLimit());
return new MenuItem(display.getCurrentPopup());
}
finally {
display.remove(interceptor);
}
}