Revision: 1274
Author: mathiasbr
Date: 2006-08-07 01:26:11 -0700 (Mon, 07 Aug 2006)
ViewCVS: http://svn.sourceforge.net/spring-rich-c/?rev=1274&view=rev
Log Message:
-----------
tests are now reliable as they check the event queue for outstanding events
Modified Paths:
--------------
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/util/OverlayHelperTests.java
Modified:
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/util/OverlayHelperTests.java
===================================================================
---
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/util/OverlayHelperTests.java
2006-08-07 08:05:17 UTC (rev 1273)
+++
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/util/OverlayHelperTests.java
2006-08-07 08:26:11 UTC (rev 1274)
@@ -15,11 +15,14 @@
*/
package org.springframework.richclient.util;
+import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
+import java.awt.EventQueue;
import java.awt.LayoutManager;
import java.awt.Rectangle;
+import java.awt.Toolkit;
import javax.swing.JComponent;
import javax.swing.JLabel;
@@ -35,11 +38,6 @@
* @since May 12, 2006 8:32:27 AM
*/
public class OverlayHelperTests extends SpringRichTestCase {
- /**
- * how long we have to sleep to wait for the asynchronously handled
attachement of overlays
- * mathiasbr: I don't know how it comes but on my system a value of 0 is
almost sufficient
- */
- private static final int SLEEPTIME = 100;
/**
* OverlayHelper installs the overlay as the View of a JScrollPane
viewport, if the component is in a JScrollPane,
@@ -75,9 +73,7 @@
final JScrollPane scrollPane = new JScrollPane(view);
- // we have to sleep here until the asynchronously attachement of
JLayeredPane and the overlay is finished
- // todo find a better way since it could be possible that this is not
the case on slow machines
- Thread.currentThread().sleep(SLEEPTIME);
+ waitUnitlEventQueueIsEmpty();
final Component viewportView = scrollPane.getViewport().getView();
@@ -95,6 +91,17 @@
.getPreferredScrollableViewportSize());
}
+ private void waitUnitlEventQueueIsEmpty() throws InterruptedException {
+ // we have to sleep here until the asynchronously attachement of
JLayeredPane and the overlay is finished
+ // todo find a better way since it could be possible that this is not
the case on slow machines
+ EventQueue eventQueue =
Toolkit.getDefaultToolkit().getSystemEventQueue();
+ AWTEvent peekEvent;
+ while((peekEvent = eventQueue.peekEvent()) != null) {
+ System.out.println("got event in queue: " + peekEvent);
+ Thread.currentThread().sleep(0);
+ }
+ }
+
/**
* Ensures that OverlayHelper will NOT implement the Scrollable interface
if the view component does not implement
* the Scrollable interface.
@@ -112,9 +119,7 @@
final JScrollPane scrollPane = new JScrollPane(view);
- // we have to sleep here until the asynchronously attachement of
JLayeredPane and the overlay is finished
- // todo find a better way since it could be possible that this is not
the case on slow machines
- Thread.currentThread().sleep(SLEEPTIME);
+ waitUnitlEventQueueIsEmpty();
final Component viewportView = scrollPane.getViewport().getView();
assertFalse(viewportView == view);
@@ -133,9 +138,7 @@
final JScrollPane scrollPane = new JScrollPane(view);
- // we have to sleep here until the asynchronously attachement of
JLayeredPane and the overlay is finished
- // todo find a better way since it could be possible that this is not
the case on slow machines
- Thread.currentThread().sleep(SLEEPTIME);
+ waitUnitlEventQueueIsEmpty();
Component viewportView = scrollPane.getViewport().getView();
assertFalse(viewportView == view);
@@ -146,9 +149,7 @@
view.add(someField);
scrollPane.setViewportView(view);
- // we have to sleep here until the asynchronously attachement of
JLayeredPane and the overlay is finished
- // todo find a better way since it could be possible that this is not
the case on slow machines
- Thread.currentThread().sleep(SLEEPTIME);
+ waitUnitlEventQueueIsEmpty();
viewportView = scrollPane.getViewport().getView();
assertFalse(viewportView == view);
@@ -159,9 +160,7 @@
view.add(someField);
scrollPane.setViewportView(view);
- // we have to sleep here until the asynchronously attachement of
JLayeredPane and the overlay is finished
- // todo find a better way since it could be possible that this is not
the case on slow machines
- Thread.currentThread().sleep(SLEEPTIME);
+ waitUnitlEventQueueIsEmpty();
viewportView = scrollPane.getViewport().getView();
assertFalse(viewportView == view);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs