1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.Set ; 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 37 public class AddModuleFilterTest extends TestBase { 38 39 public AddModuleFilterTest(String name) { 40 super(name); 41 } 42 43 private AddModuleFilter filter; 44 45 protected void setUp() throws Exception { 46 super.setUp(); 47 ModuleList ml = ModuleList.getModuleList(resolveEEPFile("suite1/action-project")); 48 Set deps = new HashSet (); 49 Iterator 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 { 59 assertMatches("boot.jar", new String [] {"org.netbeans.bootstrap"}); 61 assertMatches("project-ant.jar", new String [] {"org.netbeans.modules.project.ant"}); 63 assertMatches("demo library", new String [] {"org.netbeans.examples.modules.lib"}); 65 } 66 67 public void testClassAndPackageNameMatches() throws Exception { 68 assertMatches("callablesys", new String [] {"org.openide.util"}); assertMatches("org.openide.nodes", new String [] {"org.openide.nodes"}); 71 assertMatches("simplefileownerqueryimpl", new String [0]); 73 assertMatches("libclass", new String [] {"org.netbeans.examples.modules.lib"}); 75 assertMatches("magicaction", new String [0]); 77 assertMatches("javax.help", new String [] {"org.netbeans.modules.javahelp"}); 79 } 81 82 public void testMatchStrings() throws Exception { 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 { List matches = new ArrayList (); 89 Iterator it = filter.getMatches("systemaction").iterator(); 90 while (it.hasNext()) { 91 matches.add(((ModuleDependency) it.next()).getModuleEntry().getCodeNameBase()); 92 } 93 assertEquals(Arrays.asList(new String [] { 94 "org.openide.util", "org.netbeans.modules.editor", "org.openide.loaders", }), matches); 98 } 99 100 private void assertMatches(String text, String [] cnbs) { 101 Set matches = filter.getMatches(text); 102 Set matchedCNBs = new HashSet (); 103 Iterator it = matches.iterator(); 104 while (it.hasNext()) { 105 matchedCNBs.add(((ModuleDependency) it.next()).getModuleEntry().getCodeNameBase()); 106 } 107 assertEquals("correct matches for '" + text + "'", new HashSet (Arrays.asList(cnbs)), matchedCNBs); 108 } 109 110 } 111 | Popular Tags |