KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > AddModuleFilterTest


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.apisupport.project.ui.customizer;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Set JavaDoc;
29 import org.netbeans.modules.apisupport.project.universe.ModuleList;
30 import org.netbeans.modules.apisupport.project.TestBase;
31 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
32
33 /**
34  * Tests {@link AddModuleFilter}.
35  * @author Jesse Glick
36  */

37 public class AddModuleFilterTest extends TestBase {
38     
39     public AddModuleFilterTest(String JavaDoc name) {
40         super(name);
41     }
42     
43     private AddModuleFilter filter;
44     
45     protected void setUp() throws Exception JavaDoc {
46         super.setUp();
47         ModuleList ml = ModuleList.getModuleList(resolveEEPFile("suite1/action-project"));
48         Set JavaDoc/*<ModuleDependency>*/ deps = new HashSet JavaDoc();
49         Iterator JavaDoc it = ml.getAllEntries().iterator();
50         while (it.hasNext()) {
51             ModuleEntry entry = (ModuleEntry) it.next();
52             ModuleDependency dep = new ModuleDependency(entry);
53             deps.add(dep);
54         }
55         filter = new AddModuleFilter(deps, "some.random.module");
56     }
57     
58     public void testSimpleMatches() throws Exception JavaDoc {
59         // JAR:
60
assertMatches("boot.jar", new String JavaDoc[] {"org.netbeans.bootstrap"});
61         // Class-Path JAR:
62
assertMatches("project-ant.jar", new String JavaDoc[] {"org.netbeans.modules.project.ant"});
63         // Display name:
64
assertMatches("demo library", new String JavaDoc[] {"org.netbeans.examples.modules.lib"});
65     }
66     
67     public void testClassAndPackageNameMatches() throws Exception JavaDoc {
68         // Using binaries:
69
assertMatches("callablesys", new String JavaDoc[] {"org.openide.util"}); // org.openide.util.actions.CallableSystemAction
70
assertMatches("org.openide.nodes", new String JavaDoc[] {"org.openide.nodes"});
71         // This is an impl class, exclude it:
72
assertMatches("simplefileownerqueryimpl", new String JavaDoc[0]);
73         // Using sources:
74
assertMatches("libclass", new String JavaDoc[] {"org.netbeans.examples.modules.lib"});
75         // Impl class:
76
assertMatches("magicaction", new String JavaDoc[0]);
77         // Using class-path extensions:
78
assertMatches("javax.help", new String JavaDoc[] {"org.netbeans.modules.javahelp"});
79         // XXX test that friend APIs only match if "I" am a friend (needs API change in ModuleDependency)
80
}
81     
82     public void testMatchStrings() throws Exception JavaDoc {
83         ModuleDependency dep = (ModuleDependency) filter.getMatches("callablesys").iterator().next();
84         assertEquals(Collections.singleton("org.openide.util.actions.CallableSystemAction"), filter.getMatchesFor("callablesys", dep));
85     }
86     
87     public void testMatchOrdering() throws Exception JavaDoc { // #71995
88
List JavaDoc/*<String>*/ matches = new ArrayList JavaDoc();
89         Iterator JavaDoc it = filter.getMatches("systemaction").iterator();
90         while (it.hasNext()) {
91             matches.add(((ModuleDependency) it.next()).getModuleEntry().getCodeNameBase());
92         }
93         assertEquals(Arrays.asList(new String JavaDoc[] {
94             "org.openide.util", // etc.SystemAction: matchLevel=0
95
"org.netbeans.modules.editor", // etc.NbEditorUI.SystemActionPerformer: matchLevel=1
96
"org.openide.loaders", // etc.FileSystemAction: matchLevel=2
97
}), matches);
98     }
99     
100     private void assertMatches(String JavaDoc text, String JavaDoc[] cnbs) {
101         Set JavaDoc/*<ModuleDependency>*/ matches = filter.getMatches(text);
102         Set JavaDoc/*<String>*/ matchedCNBs = new HashSet JavaDoc();
103         Iterator JavaDoc it = matches.iterator();
104         while (it.hasNext()) {
105             matchedCNBs.add(((ModuleDependency) it.next()).getModuleEntry().getCodeNameBase());
106         }
107         assertEquals("correct matches for '" + text + "'", new HashSet JavaDoc(Arrays.asList(cnbs)), matchedCNBs);
108     }
109     
110 }
111
Popular Tags