1 19 20 package org.netbeans.beaninfo.editors; 21 22 import java.beans.PropertyEditor ; 23 import java.beans.PropertyEditorManager ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.util.Arrays ; 26 import junit.framework.TestCase; 27 import org.openide.nodes.Node; 28 29 33 public class StringArrayEditorTest extends TestCase { 34 static { 35 PropertyEditorManager.registerEditor (String [].class, StringArrayEditor.class); 36 } 37 38 public StringArrayEditorTest (String testName) { 39 super (testName); 40 } 41 42 public void testTheEditorHonoursSeparatorAttribute () throws Exception { 43 NP np = new NP (); 44 np.setValue ("item.separator", "-"); 45 46 PropertyEditor 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 [] value = (String [])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 [] { "X", "Y" }); 61 String 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 [] value; 69 70 public NP () { 71 super (String [].class); 72 } 73 74 public void setValue (Object val) throws IllegalAccessException , IllegalArgumentException , InvocationTargetException { 75 value = (String [])val; 76 } 77 78 public Object getValue () throws IllegalAccessException , InvocationTargetException { 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 |