KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.Action JavaDoc;
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 /**
32  *
33  * @author Jan Lahoda
34  */

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 JavaDoc testName) {
43         super(testName);
44     }
45
46     protected void setUp() throws Exception JavaDoc {
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 JavaDoc[] {
52             new ContextGlobalProviderImpl(),
53         });
54     }
55
56     public void testEnabledUpdated() throws Exception JavaDoc {
57         Action JavaDoc 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