1 19 package org.netbeans.jmi.javamodel.getters; 20 21 import java.io.PrintStream ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import junit.textui.TestRunner; 25 import org.netbeans.jmi.javamodel.Constructor; 26 import org.netbeans.jmi.javamodel.codegen.Utility; 27 import org.netbeans.junit.NbTestCase; 28 import org.netbeans.junit.NbTestSuite; 29 import org.netbeans.jmi.javamodel.*; 30 31 36 public class GetAnnotationTests extends NbTestCase { 37 38 JavaClass clazz; 39 JavaModelPackage pkg; 40 41 42 public GetAnnotationTests() { 43 super("GetAnnotationTests"); 44 } 45 46 public static NbTestSuite suite() { 47 NbTestSuite suite = new NbTestSuite(GetAnnotationTests.class); 48 return suite; 49 } 50 51 protected void setUp() { 52 clazz = (JavaClass) Utility.findClass("org.netbeans.test.getters.AnnotationEverywhere"); 53 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 54 } 55 56 private String [] attrsNames = { 57 "id", 58 "synopsis", 59 "engineer", 60 "date" 61 }; 62 63 public void testFieldAnnotation() { 64 PrintStream log = getLog(); 65 Field f = clazz.getField("a", false); 66 for (Iterator it0 = f.getAnnotations().iterator(); it0.hasNext(); ) { 67 Annotation ann = (Annotation) it0.next(); 68 log.println("Annotation: '" + ann.getTypeName().getName() + "'"); 69 int i = 0; 70 for (Iterator it1 = ann.getAttributeValues().iterator(); it1.hasNext(); i++) { 71 AttributeValue attr = (AttributeValue) it1.next(); 72 log.println("\tname = '" + attr.getName() + "', value = '" + attr.getValue()); 73 assertEquals(attrsNames[i], attr.getName()); 74 } 75 } 76 } 77 78 public void testConstructorAnnotation() { 79 PrintStream log = getLog(); 80 Constructor c = (Constructor) clazz.getContents().get(1); 81 log.println("Constructor: '" + c.getDeclaringClass().getName() + "':"); 82 int i = 0; 83 for (Iterator it0 = c.getAnnotations().iterator(); it0.hasNext(); i++) { 84 String name = ((Annotation) it0.next()).getTypeName().getName(); 85 log.println("\t" + name + "."); 86 assertEquals(parAnnNames[i], name); 87 } 88 } 89 90 private String [] parAnnNames = { 91 "Deprecated", 92 "AnnotationType" 93 }; 94 95 public void testParameterAnnotation() { 96 PrintStream log = getLog(); 97 Method m = (Method) clazz.getContents().get(2); 98 List l = m.getParameters(); 99 for (Iterator it0 = l.iterator(); it0.hasNext(); ) { 100 Parameter p = (Parameter) it0.next(); 101 log.println("Parameter: '" + p.getName() + "':"); 102 int i = 0; 103 for (Iterator it1 = p.getAnnotations().iterator(); it1.hasNext(); i++) { 104 String name = ((Annotation) it1.next()).getTypeName().getName(); 105 log.println("\tannotation: '" + name + "'"); 106 assertEquals(parAnnNames[i], name); 107 } 108 } 109 } 110 111 114 public static void main(String [] args) { 115 TestRunner.run(suite()); 116 } 117 118 } 119 | Popular Tags |