1 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 ; 27 28 32 public class NamespaceSelectorTest extends NbTestCase { 33 34 public NamespaceSelectorTest(java.lang.String testName) { 35 super(testName); 36 } 37 38 public static void main(java.lang.String [] args) { 39 junit.textui.TestRunner.run(new NbTestSuite (NamespaceSelectorTest.class)); 40 } 41 42 44 public void testObjectIsFound () { 45 46 Enumeration en = org.netbeans.modules.looks.TypesSearch.namesForClass( new Object ().getClass() ); 47 assertClass ("Object is found", Object .class, en.nextElement ()); 48 assertTrue ("No more items", !en.hasMoreElements()); 49 50 } 51 52 55 public void testInterfaceBeforeObject () { 56 57 class O extends Object implements Runnable { 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 .class, en.nextElement()); 64 assertClass ("Object is the last fallback", Object .class, en.nextElement ()); 65 assertTrue ("No more items", !en.hasMoreElements()); 66 67 } 68 69 71 public void testAllInterfacesAreChecked () { 72 class O extends Object implements javax.swing.Action { 74 public void actionPerformed (java.awt.event.ActionEvent ev) {} 75 public Object getValue (String s) { return null; } 76 public void putValue (String s, Object o) {} 77 public void setEnabled (boolean b) {} 78 public boolean isEnabled () { return false; } 79 public void addPropertyChangeListener (PropertyChangeListener l) {} 80 public void removePropertyChangeListener (PropertyChangeListener 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 .class, en.nextElement ()); 86 assertClass ("And the interfaces extends ActionListener", java.awt.event.ActionListener .class, en.nextElement ()); 87 assertClass ("ActionListener is a listener", java.util.EventListener .class, en.nextElement ()); 88 assertClass ("Last is as usually Object", Object .class, en.nextElement ()); 89 assertTrue ("And we are done", !en.hasMoreElements ()); 90 } 91 92 94 private static final void assertClass (String txt, Class c, Object obj) { 95 assertEquals (txt, c.getName ().replace ('.', '/'), obj); 96 } 97 98 99 100 118 } 119 | Popular Tags |