KickJava   Java API By Example, From Geeks To Geeks.

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


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 junit.framework.*;
23 import org.openide.util.Lookup;
24 import org.openide.util.lookup.AbstractLookup;
25 import org.openide.util.lookup.InstanceContent;
26 import org.openide.util.lookup.Lookups;
27 import org.openide.util.lookup.ProxyLookup;
28
29 /** Tests that a window system implementation conforms to the expected
30  * behaviour.
31  *
32  * @author Jaroslav Tulach
33  */

34 public final class WindowSystemCompatibilityTest extends Object JavaDoc {
35     /** initialize the lookup for the test */
36     public static void init() {
37         System.setProperty("org.openide.util.Lookup", WindowSystemCompatibilityTest.class.getName() + "$Lkp");
38         
39         Object JavaDoc o = Lookup.getDefault();
40         if (!(o instanceof Lkp)) {
41             Assert.fail("Wrong lookup object: " + o);
42         }
43     }
44     
45     private WindowSystemCompatibilityTest(String JavaDoc testName) {
46     }
47
48     /** Checks the default implementation.
49      */

50     public static Test suite() {
51         return suite(null);
52     }
53     
54     /** Executes the test for provided window manager.
55      */

56     public static Test suite(WindowManager wm) {
57         init();
58         
59         Object JavaDoc o = Lookup.getDefault();
60         Lkp l = (Lkp)o;
61         l.assignWM(wm);
62         
63         if (wm != null) {
64             Assert.assertEquals("Same engine found", wm, WindowManager.getDefault());
65         } else {
66             o = WindowManager.getDefault();
67             Assert.assertNotNull("Engine found", o);
68             Assert.assertEquals(DummyWindowManager.class, o.getClass());
69         }
70         
71         TestSuite ts = new TestSuite();
72         ts.addTestSuite(WindowManagerHid.class);
73         
74         return ts;
75     }
76
77     /** Default lookup used in the suite.
78      */

79     public static final class Lkp extends ProxyLookup {
80         private InstanceContent ic;
81         
82         public Lkp() {
83             super(new Lookup[0]);
84             
85             ic = new InstanceContent();
86             AbstractLookup al = new AbstractLookup(ic);
87             
88             setLookups(new Lookup[] {
89                 al, Lookups.metaInfServices(Lkp.class.getClassLoader())
90             });
91         }
92         
93         final void assignWM(WindowManager executionEngine) {
94 // ic.setPairs(java.util.Collections.EMPTY_LIST);
95
if (executionEngine != null) {
96                 ic.add(executionEngine);
97             }
98         }
99         
100         
101     }
102
103 }
104
Popular Tags