From: <tw...@us...> - 2007-01-19 18:15:05
|
Revision: 2164 http://abbot.svn.sourceforge.net/abbot/?rev=2164&view=rev Author: twall Date: 2007-01-19 10:14:56 -0800 (Fri, 19 Jan 2007) Log Message: ----------- Print warning to stderr when under eclipse (otherwise EDT exceptions get hidden) Fix showModalDialog method to avoid premature failures Modified Paths: -------------- abbot/trunk/src/abbot/util/EDTExceptionCatcher.java abbot/trunk/src/junit/extensions/abbot/ComponentTestFixture.java Modified: abbot/trunk/src/abbot/util/EDTExceptionCatcher.java =================================================================== --- abbot/trunk/src/abbot/util/EDTExceptionCatcher.java 2007-01-19 13:56:13 UTC (rev 2163) +++ abbot/trunk/src/abbot/util/EDTExceptionCatcher.java 2007-01-19 18:14:56 UTC (rev 2164) @@ -45,7 +45,12 @@ protected void exceptionCaught(Throwable thr) { if (!(thr instanceof ExitException)) { - Log.log("An exception was thrown on the EDT: " + thr, thr); + if (System.getProperty("java.class.path").indexOf("eclipse") != -1) { + Log.warn("An exception was thrown on the EDT: " + thr, thr); + } + else { + Log.log("An exception was thrown on the EDT: " + thr, thr); + } synchronized(EDTExceptionCatcher.class) { when = System.currentTimeMillis(); throwable = thr; Modified: abbot/trunk/src/junit/extensions/abbot/ComponentTestFixture.java =================================================================== --- abbot/trunk/src/junit/extensions/abbot/ComponentTestFixture.java 2007-01-19 13:56:13 UTC (rev 2163) +++ abbot/trunk/src/junit/extensions/abbot/ComponentTestFixture.java 2007-01-19 18:14:56 UTC (rev 2164) @@ -300,15 +300,25 @@ @see #showWindow(java.awt.Window,java.awt.Dimension) @see #showWindow(java.awt.Window,java.awt.Dimension,boolean) */ - protected Dialog showModalDialog(Runnable showAction) throws ComponentSearchException { - EventQueue.invokeLater(showAction); - // Install a runnable to detect if the action returns prematurely + protected Dialog showModalDialog(final Runnable showAction) throws ComponentSearchException { + final boolean[] modalRun = {false}; final boolean[] invocationFinished = { false }; EventQueue.invokeLater(new Runnable() { public void run() { - invocationFinished[0] = true; + modalRun[0] = true; + try { + showAction.run(); + } + finally { + // Detect premature Runnable return + invocationFinished[0] = true; + } } }); + while (!modalRun[0]) { + try { Thread.sleep(10); } + catch(InterruptedException e) { } + } // Wait for any modal dialog to appear Matcher matcher = new ClassMatcher(Dialog.class, true) { public boolean matches(Component c) { @@ -317,22 +327,23 @@ } }; Timer timer = new Timer(); - boolean quit = false; + boolean finished = false; while (true) { try { return (Dialog)getFinder().find(matcher); } catch(ComponentSearchException e) { if (invocationFinished[0]) { - if (quit) break; - quit = true; + // ensure we do one more check to see if the dialog is there + if (finished) break; + finished = true; } if (timer.elapsed() > 10000) throw new ComponentSearchException("Timed out waiting for dialog to be ready"); robot.sleep(); } } - throw new ComponentSearchException("No dialog was displayed"); + throw new ComponentSearchException("No dialog was displayed (premature return=" + finished + ")"); } /** Similar to {@link #showModalDialog(Runnable)}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |