1 19 20 package org.netbeans.modules.queries; 21 22 import java.io.IOException ; 23 import junit.framework.*; 24 import java.io.File ; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.spi.queries.CollocationQueryImplementation; 27 28 32 public class AlwaysRelativeCollocationQueryTest extends NbTestCase { 33 34 public AlwaysRelativeCollocationQueryTest(String testName) { 35 super(testName); 36 } 37 38 39 public void testFindRoot() throws IOException { 40 AlwaysRelativeCollocationQuery cq = new AlwaysRelativeCollocationQuery (); 41 File testRoot = this.getWorkDir(); 42 File root1 = new File (testRoot,"root1"); 43 root1.mkdirs(); 44 File root2 = new File (testRoot, "root2"); 45 root2.mkdirs(); 46 File folder1 = new File (new File (root1,"folder1_1"), "folder1_2"); 47 folder1.mkdirs(); 48 File folder2 = new File (new File (root1,"folder2_1"), "folder2_2"); 49 folder2.mkdirs(); 50 File folderExt = new File (new File (root2,"folderExt_1"), "folderExt_2"); 51 folderExt.mkdirs(); 52 53 File [] roots = new File [] { 54 root1 55 }; 56 cq.setFileSystemRoots (roots); 57 assertEquals("Wrong root of the folder1", root1, cq.findRoot(folder1)); 58 assertEquals("Wrong root of the folder2", root1, cq.findRoot(folder2)); 59 60 roots = new File [] { 61 root1, 62 root2 63 }; 64 cq.setFileSystemRoots (roots); 65 assertEquals("Wrong root of the folder1", root1, cq.findRoot(folder1)); 66 assertEquals("Wrong root of the folder2", root1, cq.findRoot(folder2)); 67 assertEquals("Wrong root of the folderExt", root2, cq.findRoot(folderExt)); 68 } 69 70 public void testAreCollocated() throws IOException { 71 AlwaysRelativeCollocationQuery cq = new AlwaysRelativeCollocationQuery (); 72 File testRoot = this.getWorkDir(); 73 File root1 = new File (testRoot,"root1"); 74 root1.mkdirs(); 75 File root2 = new File (testRoot, "root2"); 76 root2.mkdirs(); 77 File folder1 = new File (new File (root1,"folder1_1"), "folder1_2"); 78 folder1.mkdirs(); 79 File folder2 = new File (new File (root1,"folder2_1"), "folder2_2"); 80 folder2.mkdirs(); 81 File folderExt = new File (new File (root2,"folderExt_1"), "folderExt_2"); 82 folderExt.mkdirs(); 83 84 File [] roots = new File [] { 85 root1 86 }; 87 cq.setFileSystemRoots (roots); 88 assertTrue ("The folder1 should be collocated with the folder2", cq.areCollocated(folder1,folder2)); 89 90 roots = new File [] { 91 root1, 92 root2 93 }; 94 cq.setFileSystemRoots (roots); 95 assertTrue ("The folder1 should be collocated with the folder2", cq.areCollocated(folder1,folder2)); 96 assertFalse ("The folder1 should not be collocated with the folderExt", cq.areCollocated(folder1,folderExt)); 97 assertFalse ("The folder2 should not be collocated with the folderExt", cq.areCollocated(folder2,folderExt)); 98 } 99 100 } 101 | Popular Tags |