Added
Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.netbeans.beaninfo.editors; |
15 |
|
16 |
import junit.framework.*; |
17 |
import java.awt.*; |
18 |
import java.beans.*; |
19 |
import java.util.*; |
20 |
import javax.swing.JList; |
21 |
import javax.swing.JScrollPane; |
22 |
import org.openide.explorer.propertysheet.ExPropertyEditor; |
23 |
import org.openide.explorer.propertysheet.PropertyEnv; |
24 |
import org.openide.explorer.propertysheet.editors.XMLPropertyEditor; |
25 |
import org.openide.nodes.Node; |
26 |
|
27 |
/** |
28 |
* |
29 |
* @author jarda |
30 |
*/ |
31 |
public class StringArrayEditorTest extends TestCase { |
32 |
static { |
33 |
PropertyEditorManager.registerEditor (String[].class, StringArrayEditor.class); |
34 |
} |
35 |
|
36 |
public StringArrayEditorTest (String testName) { |
37 |
super (testName); |
38 |
} |
39 |
|
40 |
protected void setUp () throws Exception { |
41 |
} |
42 |
|
43 |
protected void tearDown () throws Exception { |
44 |
} |
45 |
|
46 |
public static Test suite () { |
47 |
TestSuite suite = new TestSuite(StringArrayEditorTest.class); |
48 |
|
49 |
return suite; |
50 |
} |
51 |
|
52 |
|
53 |
public void testTheEditorHonoursSeparatorAttribute () throws Exception { |
54 |
NP np = new NP (); |
55 |
np.setValue ("item.separator", "-"); |
56 |
|
57 |
PropertyEditor p = np.getPropertyEditor (); |
58 |
assertNotNull ("There is some editor", p); |
59 |
assertEquals ("It is StringArrayEditor", StringArrayEditor.class, p.getClass ()); |
60 |
((StringArrayEditor)p).readEnv (np); |
61 |
|
62 |
p.setAsText ("A-B"); |
63 |
|
64 |
String[] value = (String[])p.getValue (); |
65 |
|
66 |
assertNotNull ("Values is there", value); |
67 |
if (value.length != 2 || !"A".equals (value[0]) || !"B".equals(value[1])) { |
68 |
fail ("Unexpected arrays: " + Arrays.asList (value)); |
69 |
} |
70 |
|
71 |
p.setValue (new String[] { "X", "Y" }); |
72 |
String t = np.getPropertyEditor ().getAsText (); |
73 |
if (!"X- Y".equals (t)) { |
74 |
fail ("Wrong text: " + t); |
75 |
} |
76 |
} |
77 |
|
78 |
class NP extends Node.Property { |
79 |
public String[] value; |
80 |
|
81 |
public NP () { |
82 |
super (String[].class); |
83 |
} |
84 |
|
85 |
public void setValue (Object val) throws IllegalAccessException, IllegalArgumentException, java.lang.reflect.InvocationTargetException { |
86 |
value = (String[])val; |
87 |
} |
88 |
|
89 |
public Object getValue () throws IllegalAccessException, java.lang.reflect.InvocationTargetException { |
90 |
return value; |
91 |
} |
92 |
|
93 |
public boolean canWrite () { |
94 |
return true; |
95 |
} |
96 |
|
97 |
public boolean canRead () { |
98 |
return true; |
99 |
} |
100 |
|
101 |
|
102 |
} |
103 |
} |