1 19 20 package org.netbeans.modules.project.ui.actions; 21 22 import javax.swing.Action ; 23 import org.netbeans.api.project.TestUtil; 24 import org.netbeans.junit.NbTestCase; 25 import org.netbeans.modules.project.ui.actions.TestSupport.ChangeableLookup; 26 import org.openide.filesystems.FileObject; 27 import org.openide.loaders.DataObject; 28 import org.openide.util.ContextGlobalProvider; 29 import org.openide.util.Lookup; 30 31 35 public class SelectNodeActionTest extends NbTestCase { 36 37 private ChangeableLookup contextLookup; 38 private FileObject scratch; 39 private FileObject test; 40 private DataObject testDO; 41 42 public SelectNodeActionTest(String testName) { 43 super(testName); 44 } 45 46 protected void setUp() throws Exception { 47 contextLookup = new ChangeableLookup(); 48 scratch = TestUtil.makeScratchDir(this); 49 test = scratch.createData("test", "txt"); 50 testDO = DataObject.find(test); 51 TestUtil.setLookup(new Object [] { 52 new ContextGlobalProviderImpl(), 53 }); 54 } 55 56 public void testEnabledUpdated() throws Exception { 57 Action a = SelectNodeAction.inProjects(); 58 59 assertFalse(a.isEnabled()); 60 contextLookup.change(testDO); 61 assertTrue(a.isEnabled()); 62 contextLookup.change(); 63 assertFalse(a.isEnabled()); 64 contextLookup.change(testDO); 65 assertTrue(a.isEnabled()); 66 contextLookup.change(test); 67 assertTrue(a.isEnabled()); 68 contextLookup.change(testDO); 69 assertTrue(a.isEnabled()); 70 contextLookup.change(test); 71 assertTrue(a.isEnabled()); 72 contextLookup.change(); 73 assertFalse(a.isEnabled()); 74 } 75 76 public boolean runInEQ() { 77 return true; 78 } 79 80 private final class ContextGlobalProviderImpl implements ContextGlobalProvider { 81 82 public Lookup createGlobalContext() { 83 return contextLookup; 84 } 85 86 } 87 } 88 | Popular Tags |