KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > looks > NamespaceSelectorTest


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.netbeans.spi.looks;
21
22 import java.util.*;
23 import org.netbeans.spi.looks.*;
24
25 import org.netbeans.junit.*;
26 import java.beans.PropertyChangeListener JavaDoc;
27
28 /**
29  *
30  * @author Jaroslav Tulach
31  */

32 public class NamespaceSelectorTest extends NbTestCase {
33
34     public NamespaceSelectorTest(java.lang.String JavaDoc testName) {
35         super(testName);
36     }
37
38     public static void main(java.lang.String JavaDoc[] args) {
39         junit.textui.TestRunner.run(new NbTestSuite (NamespaceSelectorTest.class));
40     }
41
42     /** For object an object is found.
43      */

44     public void testObjectIsFound () {
45         
46         Enumeration en = org.netbeans.modules.looks.TypesSearch.namesForClass( new Object JavaDoc ().getClass() );
47         assertClass ("Object is found", Object JavaDoc.class, en.nextElement ());
48         assertTrue ("No more items", !en.hasMoreElements());
49
50     }
51     
52     /** Test that the default namespace look works correctly on a hierarchy
53      * of objects.
54      */

55     public void testInterfaceBeforeObject () {
56         
57         class O extends Object JavaDoc implements Runnable JavaDoc {
58             public void run () {};
59         }
60         
61         Enumeration en = org.netbeans.modules.looks.TypesSearch.namesForClass( new O ().getClass() );
62         assertClass ("Actual class is allways first", O.class, en.nextElement ());
63         assertClass ("Interface takes precedence", Runnable JavaDoc.class, en.nextElement());
64         assertClass ("Object is the last fallback", Object JavaDoc.class, en.nextElement ());
65         assertTrue ("No more items", !en.hasMoreElements());
66         
67     }
68     
69     /** All interfaces are introspected.
70      */

71     public void testAllInterfacesAreChecked () {
72         // Action is a interface that extends another interface
73
class O extends Object JavaDoc implements javax.swing.Action JavaDoc {
74             public void actionPerformed (java.awt.event.ActionEvent JavaDoc ev) {}
75             public Object JavaDoc getValue (String JavaDoc s) { return null; }
76             public void putValue (String JavaDoc s, Object JavaDoc o) {}
77             public void setEnabled (boolean b) {}
78             public boolean isEnabled () { return false; }
79             public void addPropertyChangeListener (PropertyChangeListener JavaDoc l) {}
80             public void removePropertyChangeListener (PropertyChangeListener JavaDoc l) {}
81         }
82         
83         Enumeration en = org.netbeans.modules.looks.TypesSearch.namesForClass( new O ().getClass());
84         assertClass ("Actual class is always first", O.class, en.nextElement ());
85         assertClass ("It implements Action interface", javax.swing.Action JavaDoc.class, en.nextElement ());
86         assertClass ("And the interfaces extends ActionListener", java.awt.event.ActionListener JavaDoc.class, en.nextElement ());
87         assertClass ("ActionListener is a listener", java.util.EventListener JavaDoc.class, en.nextElement ());
88         assertClass ("Last is as usually Object", Object JavaDoc.class, en.nextElement ());
89         assertTrue ("And we are done", !en.hasMoreElements ());
90     }
91         
92     /** Asserts name of class with a name in a namespace
93      */

94     private static final void assertClass (String JavaDoc txt, Class JavaDoc c, Object JavaDoc obj) {
95         assertEquals (txt, c.getName ().replace ('.', '/'), obj);
96     }
97     
98     
99     /** Innerclass to get access to namesFor method */
100     /*
101     private static final class L implements NamespaceLookProvider {
102                        
103         public Enumeration names (Object obj) {
104             return namesFor (obj);
105         }
106         
107         public void addChangeListener(javax.swing.event.ChangeListener listener) throws TooManyListenersException {
108         }
109         
110         public Object getKeyForObject(Object representedObject) {
111         }
112         
113         public Enumeration namesForKey(Object obj) {
114         }
115         
116     }
117     */

118 }
119
Popular Tags