1 19 package org.netbeans.modules.javacore.classindex; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.Iterator ; 24 import junit.framework.AssertionFailedError; 25 import junit.textui.TestRunner; 26 import org.netbeans.jmi.javamodel.AnnotationType; 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 34 38 public class AnnotationIndexTest extends NbTestCase { 39 40 JavaModelPackage model; 41 ClassIndex index; 42 43 44 public AnnotationIndexTest() { 45 super("AnnotationIndexTest"); 46 } 47 48 public static NbTestSuite suite() { 49 NbTestSuite suite = new NbTestSuite(AnnotationIndexTest.class); 50 return suite; 51 } 52 53 protected void setUp() { 54 JavaClass clazz = Utility.findClass("org.netbeans.test.classindex.annotation.FirstClass"); 55 model = (JavaModelPackage) clazz.refImmediatePackage(); 56 index = ClassIndex.getIndex(model); 57 } 58 59 public void testAnnotationBySNPrefix() { 60 Collection c = index.getClassesByFQNPrefix("org.netbeans.test.classindex.annotation."); 61 Collection anns = new ArrayList (); 62 for (Iterator it = c.iterator(); it.hasNext(); ) { 63 Object o = it.next(); 64 if (o instanceof AnnotationType) { 65 anns.add(o); 66 } 67 } 68 printFound(anns); 69 if (anns.size() != 3) { 70 throw new AssertionFailedError("Found #" + c.size() + " classes instead of #3."); 71 } 72 } 73 74 private void printFound(Collection c) { 75 for (Iterator it = c.iterator(); it.hasNext(); ) { 76 getLog().println(it.next()); 77 } 78 } 79 80 83 public static void main(String [] args) { 84 TestRunner.run(suite()); 85 } 86 87 } 88 | Popular Tags |