|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.spi.looks; import java.util.*; import org.netbeans.spi.looks.*; import org.netbeans.junit.*; import java.beans.PropertyChangeListener; /** * * @author Jaroslav Tulach */ public class NamespaceSelectorTest extends NbTestCase { public NamespaceSelectorTest(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(new NbTestSuite (NamespaceSelectorTest.class)); } /** For object an object is found. */ public void testObjectIsFound () { Enumeration en = org.netbeans.modules.looks.TypesSearch.namesForClass( new Object ().getClass() ); assertClass ("Object is found", Object.class, en.nextElement ()); assertTrue ("No more items", !en.hasMoreElements()); } /** Test that the default namespace look works correctly on a hierarchy * of objects. */ public void testInterfaceBeforeObject () { class O extends Object implements Runnable { public void run () {}; } Enumeration en = org.netbeans.modules.looks.TypesSearch.namesForClass( new O ().getClass() ); assertClass ("Actual class is allways first", O.class, en.nextElement ()); assertClass ("Interface takes precedence", Runnable.class, en.nextElement()); assertClass ("Object is the last fallback", Object.class, en.nextElement ()); assertTrue ("No more items", !en.hasMoreElements()); } /** All interfaces are introspected. */ public void testAllInterfacesAreChecked () { // Action is a interface that extends another interface class O extends Object implements javax.swing.Action { public void actionPerformed (java.awt.event.ActionEvent ev) {} public Object getValue (String s) { return null; } public void putValue (String s, Object o) {} public void setEnabled (boolean b) {} public boolean isEnabled () { return false; } public void addPropertyChangeListener (PropertyChangeListener l) {} public void removePropertyChangeListener (PropertyChangeListener l) {} } Enumeration en = org.netbeans.modules.looks.TypesSearch.namesForClass( new O ().getClass()); assertClass ("Actual class is always first", O.class, en.nextElement ()); assertClass ("It implements Action interface", javax.swing.Action.class, en.nextElement ()); assertClass ("And the interfaces extends ActionListener", java.awt.event.ActionListener.class, en.nextElement ()); assertClass ("ActionListener is a listener", java.util.EventListener.class, en.nextElement ()); assertClass ("Last is as usually Object", Object.class, en.nextElement ()); assertTrue ("And we are done", !en.hasMoreElements ()); } /** Asserts name of class with a name in a namespace */ private static final void assertClass (String txt, Class c, Object obj) { assertEquals (txt, c.getName ().replace ('.', '/'), obj); } /** Innerclass to get access to namesFor method */ /* private static final class L implements NamespaceLookProvider { public Enumeration names (Object obj) { return namesFor (obj); } public void addChangeListener(javax.swing.event.ChangeListener listener) throws TooManyListenersException { } public Object getKeyForObject(Object representedObject) { } public Enumeration namesForKey(Object obj) { } } */ } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.