KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > openfile > OpenCLITest


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.openfile;
21
22 import java.awt.Component JavaDoc;
23 import java.io.File JavaDoc;
24 import org.netbeans.api.sendopts.CommandLine;
25 import org.netbeans.junit.MockServices;
26 import org.netbeans.junit.NbTestCase;
27 import org.openide.explorer.ExplorerManager;
28 import org.openide.filesystems.FileObject;
29 import org.openide.filesystems.FileUtil;
30 import org.openide.nodes.Node;
31 import org.openide.nodes.NodeAcceptor;
32 import org.openide.nodes.NodeOperation;
33 import org.openide.util.UserCancelException;
34 import org.openide.windows.TopComponent;
35 import org.openide.windows.WindowManager;
36
37 /**
38  *
39  * @author Jaroslav Tulach
40  */

41 public class OpenCLITest extends NbTestCase {
42     File JavaDoc dir;
43     
44     public OpenCLITest(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     protected boolean runInEQ() {
49         return true;
50     }
51     
52     protected void setUp() throws Exception JavaDoc {
53         dir = new File JavaDoc(getWorkDir(), "tstdir");
54         dir.mkdirs();
55         
56         MockServices.setServices(MockNodeOperation.class);
57         MockNodeOperation.explored = null;
58     }
59
60     protected void tearDown() throws Exception JavaDoc {
61     }
62     
63     public void testOpenFolder() throws Exception JavaDoc {
64         CommandLine.getDefault().process(new String JavaDoc[] { "--open", dir.getPath() });
65
66         assertNotNull("A node has been explored", MockNodeOperation.explored);
67         
68         FileObject root = MockNodeOperation.explored.getLookup().lookup(FileObject.class);
69         assertNotNull("There is a file object in lookup", root);
70         
71         assertEquals("It is our dir", dir, FileUtil.toFile(root));
72     }
73     
74     public static final class MockNodeOperation extends NodeOperation {
75         public static Node explored;
76         
77         public boolean customize(Node n) {
78             fail("No customize");
79             return false;
80         }
81
82         public void explore(Node n) {
83             assertNull("No explore before", explored);
84             explored = n;
85         }
86
87         public void showProperties(Node n) {
88             fail("no props");
89         }
90
91         public void showProperties(Node[] n) {
92             fail("no props");
93         }
94
95         public Node[] select(String JavaDoc title, String JavaDoc rootTitle, Node root, NodeAcceptor acceptor, Component JavaDoc top) throws UserCancelException {
96             fail("no select");
97             return null;
98         }
99         
100     }
101 }
102
Popular Tags