KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > favorites > NodesTest


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.favorites;
21
22 import java.io.File JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collection JavaDoc;
25 import javax.swing.Action JavaDoc;
26 import junit.textui.TestRunner;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.junit.NbTestSuite;
29 import org.openide.modules.ModuleInfo;
30 import org.openide.nodes.Node;
31 import org.openide.util.Lookup;
32
33 public class NodesTest extends NbTestCase {
34     private File JavaDoc userDir, platformDir, clusterDir;
35
36     public NodesTest(String JavaDoc name) {
37         super (name);
38     }
39
40     public static void main(String JavaDoc[] args) {
41         TestRunner.run(new NbTestSuite(NodesTest.class));
42     }
43     
44     
45     protected void setUp () throws Exception JavaDoc {
46         super.setUp ();
47         
48         // initialize module system with all modules
49
Lookup.getDefault().lookup (
50             ModuleInfo.class
51         );
52     }
53     
54     public void testNoneOfTheNodesHaveShadowLinks () throws Exception JavaDoc {
55         doCheckDepth (Favorites.getNode (), 1);
56     }
57     
58     private void doCheckDepth (Node node, int depth) throws Exception JavaDoc {
59         //Limit test to 2 levels
60
if (depth > 2) {
61             return;
62         }
63         Node[] arr = node.getChildren().getNodes(true);
64         Action JavaDoc add = Actions.add();
65         Action JavaDoc remove = Actions.remove();
66         
67         for (int i = 0; i < arr.length; i++) {
68             File JavaDoc f = Favorites.fileForNode(arr[i]);
69             //First level (link) has action remove
70
//Further level has action add
71
Collection JavaDoc set = Arrays.asList (arr[i].getActions(false));
72             if (depth == 1) {
73                 if (!set.contains (remove)) {
74                     fail ("Node " + arr[i] + " does not contain action remove, but:\n" + set);
75                 }
76                 if (set.contains(add)) {
77                     fail ("Node " + arr[i] + " contains action add.");
78                 }
79             } else {
80                 if (!set.contains(add)) {
81                     fail ("Node " + arr[i] + " does not contain action, but:\n" + set);
82                 }
83                 if (set.contains (remove)) {
84                     fail ("Node " + arr[i] + " contains action remove.");
85                 }
86             }
87             
88             doCheckDepth (arr[i], depth + 1);
89         }
90     }
91 }
92
Popular Tags