public void tearDown() throws Exception {
}
@Test
public void testWaitForSwing() throws Throwable {
DialogForTesting dialog1 = new DialogForTesting(this.getClass().getName());
dialog1.addButton("foo", "bar");
DialogForTesting dialog2 = new DialogForTesting(this.getClass().getName() + ".2");
final HashSet<Window> hashWindows = new HashSet<Window>();
ITopLevelWindowListener listener = new ITopLevelWindowListener() {
public void topLevelWindowCreated(Window window) {
hashWindows.add(window);
}
public void topLevelWindowDestroyed(Window window) {
hashWindows.remove(window);
}
};
try {
WindowMonitor.getInstance().addTopLevelWindowListener(listener);
assertEquals("should be nothing up", toSet(new Object[] {}), hashWindows);
dialog1.show();
assertEquals("dialog1 should have been shown", toSet(new Object[] { dialog1 }), hashWindows);
dialog2.show();
// new Snooze(500);
assertEquals("dialog2 should have been shown", toSet(new Object[] { dialog1, dialog2 }), hashWindows);
dialog1.dispose();
dialog2.dispose();
AWTSync.sync();
assertNull("windows 1 should be closed", WindowMonitor.getInstance().getWindow(dialog1.getTitle()));
assertNull("windows 2 should be closed", WindowMonitor.getInstance().getWindow(dialog2.getTitle()));
if (hashWindows.size() != 0) {
Thread.sleep(100); // doesn't matter, we know this is a race
// condition, but who cares
assertEquals("should have disposed both", toSet(new Object[] {}), hashWindows);
}
} finally {
dialog1.dispose();
dialog2.dispose();
WindowMonitor.getInstance().removeTopLevelWindowListener(listener);
}
}