1 19 20 package org.openide.actions; 21 22 import java.lang.reflect.InvocationTargetException ; 23 import org.netbeans.junit.NbTestCase; 24 import org.openide.nodes.AbstractNode; 25 import org.openide.nodes.Children; 26 import org.openide.nodes.Node; 27 import javax.swing.Action ; 28 import org.openide.nodes.Node.Property; 29 import org.openide.nodes.Node.PropertySet; 30 31 35 public class PropertiesActionTest extends NbTestCase { 36 public PropertiesActionTest (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 void testEnableOnEmptyProperties () throws Exception { 47 testEnable (new PropertySet [0]); 48 } 49 50 public void testEnableOnNullProperties () throws Exception { 51 testEnable (null); 52 } 53 54 public void testEnableOnNotNullProperties () throws Exception { 55 PropertySet [] s = new PropertySet [] { new PropertySet () { 56 public Property[] getProperties () { 57 Property p = new Property (String .class) { 58 public boolean canRead () { 59 return true; 60 } 61 public boolean canWrite () { 62 return true; 63 } 64 public Object getValue () throws IllegalAccessException ,InvocationTargetException { 65 return null; 66 } 67 public void setValue (Object val) throws IllegalAccessException ,IllegalArgumentException ,InvocationTargetException { 68 } 69 }; 70 return new Property [] { p }; 71 } 72 } }; 73 74 testEnable (s); 75 } 76 77 private void testEnable (final PropertySet [] pros) throws Exception { 78 Node n = new AbstractNode (Children.LEAF) { 79 public PropertySet [] getPropertySets () { 80 return pros; 81 } 82 }; 83 84 85 assertEquals ("Node has the given properties.", pros, n.getPropertySets ()); 86 87 Node[] activatedNodes = new Node [] { n }; 88 89 PropertiesAction pa = (PropertiesAction) PropertiesAction.get (PropertiesAction.class); 90 Action a = pa.createContextAwareInstance (n.getLookup ()); 91 92 assertTrue ("PropertiesAction is enabled.", a.isEnabled ()); 93 } 94 95 } 96 | Popular Tags |