1 19 package org.netbeans.modules.javacore.classindex; 20 21 import java.lang.reflect.Modifier ; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import junit.framework.AssertionFailedError; 26 import junit.textui.TestRunner; 27 import org.netbeans.jmi.javamodel.JavaClass; 28 import org.netbeans.jmi.javamodel.JavaModelPackage; 29 import org.netbeans.jmi.javamodel.codegen.Utility; 30 import org.netbeans.junit.NbTestCase; 31 import org.netbeans.junit.NbTestSuite; 32 import org.netbeans.modules.javacore.ClassIndex; 33 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 34 35 42 public class ClassIndexTest extends NbTestCase { 43 private static final String NAME = "ClassIndexTest"; 44 private static final String PREFIX = "ClassIndex"; 45 46 JavaModelPackage model; 47 ClassIndex index; 48 49 50 public ClassIndexTest() { 51 super("ClassIndexTest"); 52 } 53 54 public static NbTestSuite suite() { 55 NbTestSuite suite = new NbTestSuite(ClassIndexTest.class); 56 return suite; 57 } 58 59 protected void setUp() { 60 JavaClass clazz = Utility.findClass("org.netbeans.test.classindex.index1." + NAME); 61 model = (JavaModelPackage) clazz.refImmediatePackage(); 62 index = ClassIndex.getIndex(model); 63 } 64 65 public void testCaseSensitive() { 66 Collection c = index.getClassesBySimpleName(NAME); 67 printFound(c); 68 if (c.size() != 1) { 69 throw new AssertionFailedError("Found #" + c.size() + " classes instead of #1."); 70 } 71 } 72 73 public void testCaseInsensitive() { 74 Collection c = index.getClassesBySimpleName(NAME, false); 75 printFound(c); 76 if (c.size() != 3) { 77 throw new AssertionFailedError("Found #" + c.size() + " classes instead of #3."); 78 } 79 } 80 81 public void testPrefixCaseSensitive() { 82 Collection c = index.getClassesBySNPrefix(PREFIX); 83 printFound(c); 84 if (c.size() != 2) { 85 throw new AssertionFailedError("Found #" + c.size() + " classes instead of #2."); 86 } 87 } 88 89 public void testPrefixCaseInsensitive() { 90 Collection c = index.getClassesBySNPrefix(PREFIX, false); 91 printFound(c); 92 if (c.size() != 6) { 93 throw new AssertionFailedError("Found #" + c.size() + " classes instead of #6."); 94 } 95 } 96 97 private void printFound(Collection c) { 98 for (Iterator it = c.iterator(); it.hasNext(); ) { 99 getLog().println(it.next()); 100 } 101 } 102 105 public static void main(String [] args) { 106 TestRunner.run(suite()); 107 } 108 109 } 110 | Popular Tags |