KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > execution > ExecutionCompatibilityTest


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.execution;
21
22 import junit.framework.Assert;
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25 import org.openide.execution.ExecutionEngine;
26 import org.openide.util.Lookup;
27 import org.openide.util.lookup.AbstractLookup;
28 import org.openide.util.lookup.InstanceContent;
29
30 /** Entry point to the whole execution compatibility suite.
31  *
32  * @author Jaroslav Tulach
33  */

34 public class ExecutionCompatibilityTest {
35
36     /** Creates a new instance of ExecutionCompatibilityTest */
37     private ExecutionCompatibilityTest() {
38     }
39     
40     /** Executes the execution compatibility kit on the default implementation of the
41      * ExecutionEngine.
42      */

43     public static Test suite() {
44         return suite(null);
45     }
46     
47     /** Executes the execution compatibility kit tests on the provided instance
48      * of execution engine.
49      */

50     public static Test suite(ExecutionEngine engine) {
51         System.setProperty("org.openide.util.Lookup", ExecutionCompatibilityTest.class.getName() + "$Lkp");
52         Object JavaDoc o = Lookup.getDefault();
53         if (!(o instanceof Lkp)) {
54             Assert.fail("Wrong lookup object: " + o);
55         }
56         
57         Lkp l = (Lkp)o;
58         l.assignExecutionEngine(engine);
59         
60         if (engine != null) {
61             Assert.assertEquals("Same engine found", engine, ExecutionEngine.getDefault());
62         } else {
63             o = ExecutionEngine.getDefault();
64             Assert.assertNotNull("Engine found", o);
65             Assert.assertEquals(ExecutionEngine.Trivial.class, o.getClass());
66         }
67         
68         TestSuite ts = new TestSuite();
69         ts.addTestSuite(ExecutionEngineHid.class);
70         
71         return ts;
72     }
73     
74     /** Default lookup used in the suite.
75      */

76     public static final class Lkp extends AbstractLookup {
77         private InstanceContent ic;
78         
79         public Lkp() {
80             this(new InstanceContent());
81         }
82         private Lkp(InstanceContent ic) {
83             super(ic);
84             this.ic = ic;
85         }
86         
87         final void assignExecutionEngine(ExecutionEngine executionEngine) {
88 // ic.setPairs(java.util.Collections.EMPTY_LIST);
89
if (executionEngine != null) {
90                 ic.add(executionEngine);
91             }
92         }
93         
94         
95     }
96 }
97
Popular Tags