KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > beans > CustomPropertyEditorManagerTest


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package test.beans;
8
9 import java.beans.PropertyEditor JavaDoc;
10 import java.beans.PropertyEditorManager JavaDoc;
11 import java.beans.PropertyEditorSupport JavaDoc;
12 import java.io.ObjectInput JavaDoc;
13 import java.io.ObjectInputStream JavaDoc;
14 import java.io.ObjectOutput JavaDoc;
15 import java.io.ObjectOutputStream JavaDoc;
16 import java.util.Arrays JavaDoc;
17 import java.util.List JavaDoc;
18
19 import junit.framework.TestCase;
20
21 import org.ejtools.beans.CustomPropertyEditorManager;
22
23 /**
24  * @author Laurent Etiemble
25  * @version $Revision: 1.1 $
26  */

27 public class CustomPropertyEditorManagerTest extends TestCase
28 {
29    /** Constructor for the CustomPropertyEditorManagerTest object */
30    public CustomPropertyEditorManagerTest()
31    {
32       super();
33    }
34
35
36    /**
37     * Constructor for the CustomPropertyEditorManagerTest object
38     *
39     * @param name Description of the Parameter
40     */

41    public CustomPropertyEditorManagerTest(String JavaDoc name)
42    {
43       super(name);
44    }
45
46
47    /** A unit test for JUnit */
48    public void testInitialization()
49    {
50       List JavaDoc paths = null;
51
52       String JavaDoc[] beforePaths = PropertyEditorManager.getEditorSearchPath();
53
54       // Force class loading
55
CustomPropertyEditorManager.findEditor(String JavaDoc.class);
56       String JavaDoc path = CustomPropertyEditorManager.EDITORS_PACKAGE;
57
58       String JavaDoc[] afterPaths = PropertyEditorManager.getEditorSearchPath();
59
60       paths = Arrays.asList(beforePaths);
61       if (paths.contains(path))
62       {
63          fail("Must not find " + path + " among the paths");
64       }
65
66       paths = Arrays.asList(afterPaths);
67       if (!paths.contains(path))
68       {
69          fail("Must find " + path + " among the paths");
70       }
71    }
72
73
74    /** A unit test for JUnit */
75    public void testSearch()
76    {
77       PropertyEditor JavaDoc pe = null;
78
79       pe = CustomPropertyEditorManager.findEditor(String JavaDoc.class);
80       assertNotNull("Must find at least one property editor", pe);
81
82       pe = CustomPropertyEditorManager.findEditor(Thread JavaDoc.class);
83       assertNull("Must not find a property editor", pe);
84
85       PropertyEditorManager.registerEditor(ObjectInput JavaDoc.class, InputStreamPropertyEditor.class);
86       PropertyEditorManager.registerEditor(ObjectOutput JavaDoc.class, OutputStreamPropertyEditor.class);
87
88       pe = CustomPropertyEditorManager.findEditor(ObjectInputStream JavaDoc.class);
89       assertNotNull("Must find one property editor", pe);
90       assertEquals("Must find one property editor", pe.getClass(), InputStreamPropertyEditor.class);
91
92       pe = CustomPropertyEditorManager.findEditor(ObjectOutputStream JavaDoc.class);
93       assertNotNull("Must find one property editor", pe);
94       assertEquals("Must find one property editor", pe.getClass(), OutputStreamPropertyEditor.class);
95    }
96
97
98    /**
99     * Description of the Class
100     *
101     * @author Laurent Etiemble
102     * @version $Revision: 1.1 $
103     */

104    public static class InputStreamPropertyEditor extends PropertyEditorSupport JavaDoc
105    {
106    }
107
108
109    /**
110     * Description of the Class
111     *
112     * @author Laurent Etiemble
113     * @version $Revision: 1.1 $
114     */

115    public static class OutputStreamPropertyEditor extends PropertyEditorSupport JavaDoc
116    {
117    }
118 }
119
Popular Tags