KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > windows > WindowManagerHid


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.windows;
21
22 import javax.swing.SwingUtilities JavaDoc;
23 import org.netbeans.junit.NbTestCase;
24
25 /** A piece of the test compatibility suite for the execution APIs.
26  *
27  * @author Jaroslav Tulach
28  */

29 public class WindowManagerHid extends NbTestCase {
30     
31     public WindowManagerHid(String JavaDoc testName) {
32         super(testName);
33     }
34     
35     public void testGetDefault() {
36         WindowManager result = WindowManager.getDefault();
37         assertNotNull(result);
38     }
39     
40     public void testInvokeWhenUIReady() throws Exception JavaDoc {
41         class R implements Runnable JavaDoc {
42             public boolean started;
43             public boolean finished;
44             public boolean block;
45             
46             public synchronized void run() {
47                 assertTrue("Runs only in AWT thread", SwingUtilities.isEventDispatchThread());
48                 try {
49                     started = true;
50                     notifyAll();
51                     if (block) {
52                         wait();
53                     }
54                 } catch (InterruptedException JavaDoc ex) {
55                     ex.printStackTrace();
56                 }
57                 finished = true;
58                 notifyAll();
59             }
60         }
61         
62         R run = new R();
63         R snd = new R();
64         
65         WindowManager wm = WindowManager.getDefault();
66         synchronized (run) {
67             wm.invokeWhenUIReady(run);
68             run.block = true;
69             run.wait();
70         }
71         assertTrue("started", run.started);
72         assertFalse("but not finished", run.finished);
73         
74         wm.invokeWhenUIReady(snd);
75         
76         Thread.sleep(100);
77         
78         assertFalse("Not started", snd.started);
79         synchronized (snd) {
80             synchronized (run) {
81                 run.notifyAll();
82                 run.wait();
83             }
84             assertTrue("run is finished", run.finished);
85             snd.wait();
86             assertTrue("snd also finished", snd.finished);
87         }
88     }
89 }
90
Popular Tags