KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > beaninfo > editors > FindEditorTest


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.beaninfo.editors;
21
22 import java.beans.PropertyEditorManager JavaDoc;
23 import junit.framework.AssertionFailedError;
24 import junit.textui.TestRunner;
25 import org.netbeans.junit.*;
26 import java.io.InputStream JavaDoc;
27 import java.lang.reflect.*;
28 import java.util.HashMap JavaDoc;
29
30 /** Test finding of property editors registred by core.
31  * @author Jiri Rechtacek
32  */

33 public class FindEditorTest extends NbTestCase {
34
35     static {
36         //issue 31879, force registration of NB editors so this
37
//test can pass when editor tests are run standalone
38
org.netbeans.core.CoreBridgeImpl.getDefault().registerPropertyEditors();
39     }
40     
41     public FindEditorTest(String JavaDoc name) {
42         super(name);
43     }
44     
45     public static void main(String JavaDoc[] args) {
46         TestRunner.run(new NbTestSuite(FindEditorTest.class));
47     }
48     
49     public void testFindStringEditor () throws Exception JavaDoc {
50         assertFind (String JavaDoc.class, org.netbeans.beaninfo.editors.StringEditor.class);
51     }
52
53     public void testFindStringArrayEditor () throws Exception JavaDoc {
54         assertFind ((new String JavaDoc[] { "" }).getClass (), org.netbeans.beaninfo.editors.StringArrayEditor.class);
55     }
56
57     public void testFindDataObjectEditor () throws Exception JavaDoc {
58         assertFind (org.openide.loaders.DataObject.class, org.netbeans.beaninfo.editors.DataObjectEditor.class);
59     }
60
61     public void testFindDataObjectArrayEditor () throws Exception JavaDoc {
62         org.openide.filesystems.FileObject fo = org.openide.filesystems.Repository.getDefault ().getDefaultFileSystem ().getRoot ();
63         Object JavaDoc obj = new org.openide.loaders.DataObject[] { org.openide.loaders.DataObject.find (fo) };
64         assertFind (obj.getClass (), org.netbeans.beaninfo.editors.DataObjectArrayEditor.class);
65     }
66     
67     private void assertFind (Class JavaDoc propertyTypeClass, Class JavaDoc editorClass) {
68         assertNotNull ("PropertyEditor for " + propertyTypeClass + " found.", PropertyEditorManager.findEditor (propertyTypeClass));
69         assertEquals ("Editor is instance of ", editorClass, PropertyEditorManager.findEditor (propertyTypeClass).getClass ());
70     }
71 }
72
Popular Tags