KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > propertysheet > EnumPropertyEditorTest


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.openide.explorer.propertysheet;
21
22 import java.beans.PropertyEditor JavaDoc;
23 import java.lang.reflect.InvocationTargetException JavaDoc;
24 import java.util.Arrays JavaDoc;
25 import org.netbeans.junit.NbTestCase;
26 import org.openide.nodes.PropertySupport;
27
28 /**
29  * Check that enumeration types have some kind of minimal proped.
30  * @author Jesse Glick
31  */

32 public class EnumPropertyEditorTest extends NbTestCase {
33
34     public EnumPropertyEditorTest(String JavaDoc name) {
35         super(name);
36     }
37
38     public void testEnumPropEd() throws Exception JavaDoc {
39         EProp prop = new EProp();
40         PropertyEditor JavaDoc ed = PropUtils.getPropertyEditor(prop);
41         assertFalse(ed.supportsCustomEditor());
42         assertFalse(ed.isPaintable());
43         String JavaDoc[] tags = ed.getTags();
44         assertNotNull(tags);
45         assertEquals("[CHOCOLATE, VANILLA, STRAWBERRY]", Arrays.toString(tags));
46         assertEquals(E.VANILLA, ed.getValue());
47         assertEquals("VANILLA", ed.getAsText());
48         ed.setAsText("STRAWBERRY");
49         assertEquals(E.STRAWBERRY, ed.getValue());
50         assertEquals(E.class.getName().replace('$', '.') + ".STRAWBERRY", ed.getJavaInitializationString());
51     }
52
53     public void testNulls() throws Exception JavaDoc {
54         EProp prop = new EProp();
55         PropertyEditor JavaDoc ed = PropUtils.getPropertyEditor(prop);
56         ed.setAsText("");
57         assertEquals(null, ed.getValue());
58         assertEquals("", ed.getAsText());
59         assertEquals("null", ed.getJavaInitializationString());
60     }
61
62     public enum E {
63         CHOCOLATE, VANILLA, STRAWBERRY
64     }
65
66     private static class EProp extends PropertySupport.ReadWrite {
67
68         private E e = E.VANILLA;
69
70         public EProp() {
71             super("eval", E.class, "E Val", "E value");
72         }
73
74         public Object JavaDoc getValue() throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
75             return e;
76         }
77
78         public void setValue(Object JavaDoc val) throws IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
79             e = (E) val;
80         }
81
82     }
83
84 }
85
Popular Tags