KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ui > actions > SetMainProjectTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.project.ui.actions;
21
22 import java.io.IOException JavaDoc;
23 import java.lang.ref.WeakReference JavaDoc;
24 import javax.swing.JMenu JavaDoc;
25 import javax.swing.JMenuItem JavaDoc;
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 JavaDoc name) {
39         super( name );
40     }
41
42     public void setUp() throws Exception JavaDoc {
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 JavaDoc<?> ref = new WeakReference JavaDoc<Object JavaDoc>(a);
64         
65         a = null;
66         
67         assertGC("SetMainProject action's instance can be freed:", ref);
68     }
69     
70     public void test70835() throws IOException JavaDoc {
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 JavaDoc item = a.getMenuPresenter();
92         
93         assertTrue(item instanceof JMenu JavaDoc);
94         
95         JMenu JavaDoc menu = (JMenu JavaDoc) item;
96         
97         item = null;
98         
99         assertEquals(2, menu.getItemCount());
100         assertTrue(menu.isEnabled());
101         
102         WeakReference JavaDoc<?> menuRef = new WeakReference JavaDoc<Object JavaDoc>(menu);
103         WeakReference JavaDoc<?> actionRef = new WeakReference JavaDoc<Object JavaDoc>(a);
104         
105         a = null;
106         
107         try {
108             assertGC("", actionRef);
109         } catch (Error JavaDoc e) {
110             //ignore....
111
}
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