1 19 20 package org.netbeans.modules.project.ui.actions; 21 22 import java.io.IOException ; 23 import java.lang.ref.WeakReference ; 24 import javax.swing.JMenu ; 25 import javax.swing.JMenuItem ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectManager; 28 import org.netbeans.junit.MockServices; 29 import org.netbeans.junit.NbTestCase; 30 import org.netbeans.modules.project.ui.OpenProjectList; 31 import org.netbeans.modules.project.ui.actions.ProjectActionTest.ActionCreator; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.util.Lookup; 35 36 public class SetMainProjectTest extends NbTestCase { 37 38 public SetMainProjectTest(String name) { 39 super( name ); 40 } 41 42 public void setUp() throws Exception { 43 super.setUp(); 44 45 MockServices.setServices(TestSupport.TestProjectFactory.class); 46 clearWorkDir (); 47 } 48 49 public boolean runInEQ () { 50 return true; 51 } 52 53 public void testAcceleratorsPropagated() { 54 ProjectActionTest.doTestAcceleratorsPropagated(new ActionCreator() { 55 public ProjectAction create(Lookup l) { 56 return new SetMainProject(l); 57 } 58 }, false); 59 } 60 61 public void test70368() { 62 SetMainProject a = new SetMainProject(); 63 WeakReference <?> ref = new WeakReference <Object >(a); 64 65 a = null; 66 67 assertGC("SetMainProject action's instance can be freed:", ref); 68 } 69 70 public void test70835() throws IOException { 71 FileObject workDir = FileUtil.toFileObject (getWorkDir ()); 72 73 assertNotNull(workDir); 74 75 FileObject f1 = TestSupport.createTestProject (workDir, "project1"); 76 FileObject f2 = TestSupport.createTestProject (workDir, "project2"); 77 78 assertNotNull(f1); 79 assertNotNull(f2); 80 81 Project p1 = ProjectManager.getDefault().findProject(f1); 82 Project p2 = ProjectManager.getDefault().findProject(f2); 83 84 assertNotNull(p1); 85 assertNotNull(p2); 86 87 OpenProjectList.getDefault().open(new Project[] {p1, p2}, false); 88 89 SetMainProject a = new SetMainProject(); 90 91 JMenuItem item = a.getMenuPresenter(); 92 93 assertTrue(item instanceof JMenu ); 94 95 JMenu menu = (JMenu ) item; 96 97 item = null; 98 99 assertEquals(2, menu.getItemCount()); 100 assertTrue(menu.isEnabled()); 101 102 WeakReference <?> menuRef = new WeakReference <Object >(menu); 103 WeakReference <?> actionRef = new WeakReference <Object >(a); 104 105 a = null; 106 107 try { 108 assertGC("", actionRef); 109 } catch (Error e) { 110 } 112 113 OpenProjectList.getDefault().close(new Project[] {p1}, false); 114 115 assertEquals(1, menu.getItemCount()); 116 assertTrue(menu.isEnabled()); 117 118 OpenProjectList.getDefault().close(new Project[] {p2}, false); 119 120 assertEquals(0, menu.getItemCount()); 121 assertFalse(menu.isEnabled()); 122 123 OpenProjectList.getDefault().open(new Project[] {p1}, false); 124 125 assertEquals(1, menu.getItemCount()); 126 assertTrue(menu.isEnabled()); 127 128 menu = null; 129 130 assertGC("", menuRef); 131 assertGC("", actionRef); 132 } 133 } 134 | Popular Tags |