/* * Issue71763Test.java * NetBeans JUnit based test * * Created on 15 de agosto de 2006, 19:49 */ package org.openide.util.actions; import java.io.IOException; import javax.swing.Action; import junit.framework.*; import org.netbeans.junit.*; import org.openide.actions.ActionsInfraHid; import org.openide.actions.SaveAction; import org.openide.cookies.SaveCookie; import org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.openide.util.lookup.Lookups; /** * * @author JAVIER */ public class Issue71764Test extends NbTestCase { public Issue71764Test(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { TestSuite suite = new NbTestSuite(Issue71764Test.class); return suite; } // Add test methods here, they have to start with 'test' name. // for example: // public void testHello() {} public void test71764() { ActionsInfraHid.UsefulThings ut = ActionsInfraHid.UT; NodeAction saveAction = (NodeAction) SaveAction.findObject(SaveAction.class,true); Node node = new TestNode(); Action a = saveAction.createContextAwareInstance (Lookups.singleton (node)); assertTrue("Context Aware Action should have been enabled",a.isEnabled()); assertFalse("Global Action should not be enabled yet", saveAction.isEnabled()); saveAction.addNotify(); ut.setCurrentNodes(new Node[] {node}); Node[] nodes = ut.getActivatedNodes(); assertTrue("Global Action is enabled", saveAction.isEnabled()); } class TestNode extends AbstractNode { public TestNode() { super(Children.LEAF); getCookieSet().add(new SaveCookie() { public void save() throws IOException { System.out.println("Save cookie called"); } }); } } }