KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > queries > AlwaysRelativeCollocationQueryTest


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.queries;
21
22 import java.io.IOException JavaDoc;
23 import junit.framework.*;
24 import java.io.File JavaDoc;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.spi.queries.CollocationQueryImplementation;
27
28 /**
29  *
30  * @author Tomas Zezula
31  */

32 public class AlwaysRelativeCollocationQueryTest extends NbTestCase {
33
34     public AlwaysRelativeCollocationQueryTest(String JavaDoc testName) {
35         super(testName);
36     }
37
38
39     public void testFindRoot() throws IOException JavaDoc {
40         AlwaysRelativeCollocationQuery cq = new AlwaysRelativeCollocationQuery ();
41         File JavaDoc testRoot = this.getWorkDir();
42         File JavaDoc root1 = new File JavaDoc (testRoot,"root1");
43         root1.mkdirs();
44         File JavaDoc root2 = new File JavaDoc (testRoot, "root2");
45         root2.mkdirs();
46         File JavaDoc folder1 = new File JavaDoc (new File JavaDoc (root1,"folder1_1"), "folder1_2");
47         folder1.mkdirs();
48         File JavaDoc folder2 = new File JavaDoc (new File JavaDoc (root1,"folder2_1"), "folder2_2");
49         folder2.mkdirs();
50         File JavaDoc folderExt = new File JavaDoc (new File JavaDoc (root2,"folderExt_1"), "folderExt_2");
51         folderExt.mkdirs();
52         
53         File JavaDoc[] roots = new File JavaDoc[] {
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 JavaDoc[] {
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 JavaDoc {
71         AlwaysRelativeCollocationQuery cq = new AlwaysRelativeCollocationQuery ();
72         File JavaDoc testRoot = this.getWorkDir();
73         File JavaDoc root1 = new File JavaDoc (testRoot,"root1");
74         root1.mkdirs();
75         File JavaDoc root2 = new File JavaDoc (testRoot, "root2");
76         root2.mkdirs();
77         File JavaDoc folder1 = new File JavaDoc (new File JavaDoc (root1,"folder1_1"), "folder1_2");
78         folder1.mkdirs();
79         File JavaDoc folder2 = new File JavaDoc (new File JavaDoc (root1,"folder2_1"), "folder2_2");
80         folder2.mkdirs();
81         File JavaDoc folderExt = new File JavaDoc (new File JavaDoc (root2,"folderExt_1"), "folderExt_2");
82         folderExt.mkdirs();
83         
84         File JavaDoc[] roots = new File JavaDoc[] {
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 JavaDoc[] {
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