1 19 20 package org.openide.explorer.propertysheet; 21 22 import java.beans.PropertyEditor ; 23 import java.lang.reflect.InvocationTargetException ; 24 import java.util.Arrays ; 25 import org.netbeans.junit.NbTestCase; 26 import org.openide.nodes.PropertySupport; 27 28 32 public class EnumPropertyEditorTest extends NbTestCase { 33 34 public EnumPropertyEditorTest(String name) { 35 super(name); 36 } 37 38 public void testEnumPropEd() throws Exception { 39 EProp prop = new EProp(); 40 PropertyEditor ed = PropUtils.getPropertyEditor(prop); 41 assertFalse(ed.supportsCustomEditor()); 42 assertFalse(ed.isPaintable()); 43 String [] 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 { 54 EProp prop = new EProp(); 55 PropertyEditor 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 getValue() throws IllegalAccessException , InvocationTargetException { 75 return e; 76 } 77 78 public void setValue(Object val) throws IllegalAccessException , IllegalArgumentException , InvocationTargetException { 79 e = (E) val; 80 } 81 82 } 83 84 } 85 | Popular Tags |