KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > classindex > AnnotationIndexTest


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 package org.netbeans.modules.javacore.classindex;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Iterator JavaDoc;
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 /**
35  *
36  * @author Pavel Flaska
37  */

38 public class AnnotationIndexTest extends NbTestCase {
39
40     JavaModelPackage model;
41     ClassIndex index;
42     
43     /** Creates a new instance of AnnotationIndexTest */
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 JavaDoc c = index.getClassesByFQNPrefix("org.netbeans.test.classindex.annotation.");
61         Collection JavaDoc anns = new ArrayList JavaDoc();
62         for (Iterator JavaDoc it = c.iterator(); it.hasNext(); ) {
63             Object JavaDoc 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 JavaDoc c) {
75         for (Iterator JavaDoc it = c.iterator(); it.hasNext(); ) {
76             getLog().println(it.next());
77         }
78     }
79
80     /**
81      * @param args the command line arguments
82      */

83     public static void main(String JavaDoc[] args) {
84         TestRunner.run(suite());
85     }
86     
87 }
88
Popular Tags