1 19 20 package org.netbeans.modules.favorites; 21 22 import java.io.File ; 23 import java.util.Arrays ; 24 import java.util.Collection ; 25 import javax.swing.Action ; 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 userDir, platformDir, clusterDir; 35 36 public NodesTest(String name) { 37 super (name); 38 } 39 40 public static void main(String [] args) { 41 TestRunner.run(new NbTestSuite(NodesTest.class)); 42 } 43 44 45 protected void setUp () throws Exception { 46 super.setUp (); 47 48 Lookup.getDefault().lookup ( 50 ModuleInfo.class 51 ); 52 } 53 54 public void testNoneOfTheNodesHaveShadowLinks () throws Exception { 55 doCheckDepth (Favorites.getNode (), 1); 56 } 57 58 private void doCheckDepth (Node node, int depth) throws Exception { 59 if (depth > 2) { 61 return; 62 } 63 Node[] arr = node.getChildren().getNodes(true); 64 Action add = Actions.add(); 65 Action remove = Actions.remove(); 66 67 for (int i = 0; i < arr.length; i++) { 68 File f = Favorites.fileForNode(arr[i]); 69 Collection 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 |