1 19 20 package org.netbeans.modules.favorites; 21 22 import java.io.File ; 23 import java.util.Arrays ; 24 import java.util.HashSet ; 25 import junit.textui.TestRunner; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.junit.NbTestSuite; 28 import org.openide.filesystems.FileUtil; 29 import org.openide.loaders.DataFolder; 30 import org.openide.modules.ModuleInfo; 31 import org.openide.nodes.Node; 32 import org.openide.util.Lookup; 33 34 public class RootsTest extends NbTestCase { 35 private File userDir, platformDir, clusterDir; 36 37 public RootsTest(String name) { 38 super (name); 39 } 40 41 public static void main(String [] args) { 42 TestRunner.run(new NbTestSuite(RootsTest.class)); 43 } 44 45 46 protected void setUp () throws Exception { 47 super.setUp (); 48 49 Lookup.getDefault().lookup ( 51 ModuleInfo.class 52 ); 53 54 68 } 69 70 71 98 99 public void testLinkToHomeDirIsThere () throws Exception { 100 Node[] arr = Favorites.getNode ().getChildren ().getNodes (true); 101 102 File home = new File (System.getProperty("user.home")).getCanonicalFile(); 103 104 HashSet folders = new HashSet (); 105 for (int i = 0; i < arr.length; i++) { 106 DataFolder f = (DataFolder)arr[i].getCookie(DataFolder.class); 107 if (f == null) continue; 108 109 folders.add (f); 110 111 File file = FileUtil.toFile ( 112 f.getPrimaryFile() 113 ); 114 assertNotNull ("All folders have files", file); 115 116 file = file.getCanonicalFile(); 117 118 if (file.equals (home)) { 119 return; 120 } 121 } 122 123 fail ("none of the folders represent user home: " + home + "\n" + folders); 124 } 125 126 127 public void testNodesUnderRootRepresentTheirFiles () throws Exception { 128 HashSet roots = new HashSet (Arrays.asList (File.listRoots())); 129 130 Node[] arr = Favorites.getNode ().getChildren ().getNodes (true); 131 132 for (int i = 0; i < arr.length; i++) { 133 File f = Favorites.fileForNode (arr[i]); 134 if (roots.remove (f)) { 135 Node[] nexts = arr[i].getChildren().getNodes (true); 136 for (int j = 0; j < nexts.length; j++) { 137 File file = Favorites.fileForNode (nexts[i]); 138 assertNotNull ("For node: " + nexts[i] + " there has to be file", file); 139 assertEquals ("Correct parent for " + nexts[i], f, file.getParentFile()); 140 } 141 } 142 } 143 } 144 } 145 | Popular Tags |