001: package org.uispec4j;
002:
003: import org.uispec4j.utils.ArrayUtils;
004: import org.uispec4j.utils.Functor;
005: import org.uispec4j.utils.Utils;
006: import org.uispec4j.xml.XmlAssert;
007:
008: import javax.swing.*;
009: import java.util.ArrayList;
010: import java.util.List;
011:
012: public class DesktopTest extends UIComponentTestCase {
013:
014: private JDesktopPane jDesktopPane = new JDesktopPane();
015: private Desktop desktop;
016:
017: protected void setUp() throws Exception {
018: super .setUp();
019: jDesktopPane.setName("myDesktop");
020: desktop = new Desktop(jDesktopPane);
021: }
022:
023: public void testGetComponentTypeName() throws Exception {
024: assertEquals("desktop", desktop.getDescriptionTypeName());
025: }
026:
027: public void testGetDescription() throws Exception {
028: XmlAssert.assertEquivalent("<desktop name='myDesktop'/>",
029: desktop.getDescription());
030: }
031:
032: public void testFactory() throws Exception {
033: checkFactory(new JProgressBar(), ProgressBar.class);
034: }
035:
036: protected UIComponent createComponent() {
037: return new Desktop(jDesktopPane);
038: }
039:
040: public void testGetWindows() throws Exception {
041: assertEquals(0, desktop.getWindows().length);
042:
043: jDesktopPane.add(new JInternalFrame("frame1"));
044: jDesktopPane.add(new JInternalFrame("frame2"));
045: Window[] windows = desktop.getWindows();
046: List titles = new ArrayList();
047: for (int i = 0; i < windows.length; i++) {
048: titles.add(windows[i].getTitle());
049: }
050: ArrayUtils.assertEquals(new String[] { "frame1", "frame2" },
051: titles);
052: }
053:
054: public void testAssertContainsWindow() throws Exception {
055: jDesktopPane.add(new JInternalFrame("frame1"));
056: assertTrue(desktop.containsWindow("frame1"));
057:
058: checkAssertionFails(desktop.containsWindow("unknown"),
059: "No window with title 'unknown' found");
060: }
061:
062: public void testGetWindow() throws Exception {
063: JInternalFrame internalFrame = new JInternalFrame("frame1");
064: jDesktopPane.add(internalFrame);
065: Window window = desktop.getWindow("frame1");
066: assertEquals("frame1", window.getTitle());
067: assertSame(internalFrame, window.getAwtComponent());
068: }
069:
070: public void testGetWindowError() throws Exception {
071: checkAssertionFailedError(new Functor() {
072: public void run() throws Exception {
073: desktop.getWindow("unknown");
074: }
075: }, "Window 'unknown' not found");
076: }
077:
078: public void testGetWindowWaitsForTheWindowToAppear()
079: throws Exception {
080: UISpec4J.setWindowInterceptionTimeLimit(100);
081: final JInternalFrame internalFrame = new JInternalFrame(
082: "frame1");
083: Thread thread = new Thread() {
084: public void run() {
085: Utils.sleep(30);
086: jDesktopPane.add(internalFrame);
087: }
088: };
089: thread.start();
090: Window window = desktop.getWindow("frame1");
091: assertSame(internalFrame, window.getAwtComponent());
092: }
093:
094: public void testGetWindowWithTitleAmbiguityError() throws Exception {
095: jDesktopPane.add(new JInternalFrame("frame"));
096: jDesktopPane.add(new JInternalFrame("frame"));
097: checkAssertionFailedError(new Functor() {
098: public void run() throws Exception {
099: desktop.getWindow("frame");
100: }
101: }, "There are several windows with title 'frame'");
102:
103: }
104: }
|