1 19 20 package org.openide.util.actions; 21 22 import java.io.IOException ; 23 import junit.framework.*; 24 import org.netbeans.junit.*; 25 import org.openide.cookies.SaveCookie; 26 import org.openide.nodes.AbstractNode; 27 import org.openide.nodes.Children; 28 import org.openide.nodes.Node; 29 import org.openide.util.ContextGlobalProvider; 30 import org.openide.util.HelpCtx; 31 import org.openide.util.Lookup; 32 import org.openide.util.actions.NodeAction; 33 import org.openide.util.lookup.Lookups; 34 35 38 public class Issue71764Test extends NbTestCase { 39 40 public Issue71764Test(java.lang.String testName) { 41 super(testName); 42 } 43 44 public static void main(java.lang.String [] args) { 45 junit.textui.TestRunner.run(suite()); 46 } 47 48 public static Test suite() { 49 TestSuite suite = new NbTestSuite(Issue71764Test.class); 50 return suite; 51 } 52 53 public void test71764() { 54 MockServices.setServices(ContextProvider.class); 55 56 ContextProvider provider = Lookup.getDefault().lookup(ContextProvider.class); 57 assertNotNull ("ContextProvider is not null.", provider); 58 59 NodeAction action = (NodeAction) new TestAction (); 60 Node node = new TestNode(); 61 62 assertFalse("Global Action should not be enabled yet", action.isEnabled()); 63 64 ContextProvider.current = node; 65 provider.getLookup().lookup(Object .class); 66 67 assertTrue("Global Action is enabled", action.isEnabled()); 68 } 69 70 class TestNode extends AbstractNode { 71 public TestNode() { 72 super(Children.LEAF); 73 getCookieSet().add(new SaveCookie() { 74 public void save() throws IOException { 75 System.out.println("Save cookie called"); 76 } 77 }); 78 } 79 } 80 81 public static class ContextProvider implements ContextGlobalProvider, Lookup.Provider { 82 static Node current; 83 Lookup lookup = Lookups.proxy (this ); 84 85 public Lookup createGlobalContext() { 86 return lookup; 87 } 88 89 public Lookup getLookup() { 90 return current == null ? Lookup.EMPTY : current.getLookup(); 91 } 92 } 93 94 public static class TestAction extends CookieAction { 95 protected int mode() { 96 return MODE_EXACTLY_ONE; 97 } 98 99 protected Class [] cookieClasses() { 100 return new Class [] {SaveCookie.class}; 101 } 102 103 protected void performAction(Node[] activatedNodes) { 104 assert false; 105 } 106 public String getName() { 107 return "TestAction"; 108 } 109 public HelpCtx getHelpCtx() { 110 return null; 111 } 112 protected boolean asynchronous() { 113 return false; 114 } 115 } 116 } 117 | Popular Tags |