KickJava   Java API By Example, From Geeks To Geeks.

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


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.PropertyEditor JavaDoc;
23 import java.beans.PropertyEditorManager JavaDoc;
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import junit.framework.TestCase;
27 import org.openide.nodes.Node;
28
29 /**
30  *
31  * @author jarda
32  */

33 public class StringArrayEditorTest extends TestCase {
34     static {
35         PropertyEditorManager.registerEditor (String JavaDoc[].class, StringArrayEditor.class);
36     }
37
38     public StringArrayEditorTest (String JavaDoc testName) {
39         super (testName);
40     }
41
42     public void testTheEditorHonoursSeparatorAttribute () throws Exception JavaDoc {
43         NP np = new NP ();
44         np.setValue ("item.separator", "-");
45         
46         PropertyEditor JavaDoc p = np.getPropertyEditor ();
47         assertNotNull ("There is some editor", p);
48         assertEquals ("It is StringArrayEditor", StringArrayEditor.class, p.getClass ());
49         ((StringArrayEditor)p).readEnv (np);
50         
51         p.setAsText ("A-B");
52         
53         String JavaDoc[] value = (String JavaDoc[])p.getValue ();
54         
55         assertNotNull ("Values is there", value);
56         if (value.length != 2 || !"A".equals (value[0]) || !"B".equals(value[1])) {
57             fail ("Unexpected arrays: " + Arrays.asList (value));
58         }
59         
60         p.setValue (new String JavaDoc[] { "X", "Y" });
61         String JavaDoc t = np.getPropertyEditor ().getAsText ();
62         if (!"X- Y".equals (t)) {
63             fail ("Wrong text: " + t);
64         }
65     }
66     
67     class NP extends Node.Property {
68         public String JavaDoc[] value;
69         
70         public NP () {
71             super (String JavaDoc[].class);
72         }
73
74         public void setValue (Object JavaDoc val) throws IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
75             value = (String JavaDoc[])val;
76         }
77
78         public Object JavaDoc getValue () throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
79             return value;
80         }
81
82         public boolean canWrite () {
83             return true;
84         }
85
86         public boolean canRead () {
87             return true;
88         }
89         
90         
91     }
92 }
93
Popular Tags