1 19 package org.netbeans.jmi.javamodel.getters; 20 21 import java.io.PrintStream ; 22 import junit.textui.TestRunner; 23 import org.netbeans.jmi.javamodel.codegen.Utility; 24 import org.netbeans.junit.NbTestCase; 25 import org.netbeans.junit.NbTestSuite; 26 import org.netbeans.jmi.javamodel.*; 27 28 33 public class AnnTypeAttrTest extends NbTestCase { 34 35 private static String [] correctIdentifiers = { 36 "id", 37 "synopsis", 38 "engineer", 39 "date" 40 }; 41 42 private static String [] correctDefValuesText = { 43 null, 44 "\"MaM likes M&M's.\"", 45 null, 46 null 47 }; 48 49 private static String [] correctTypeNames = { 50 "int", 51 "String", 52 "String", 53 "String" 54 }; 55 56 private static String [] correctTypes = { 57 "int", 58 "java.lang.String", 59 "java.lang.String", 60 "java.lang.String" 61 }; 62 63 AnnotationType clazz; 64 JavaModelPackage pkg; 65 Attribute[] attribute; 66 67 68 public AnnTypeAttrTest() { 69 super("AnnTypeAttrTest"); 70 attribute = new Attribute[4]; 71 } 72 73 public static NbTestSuite suite() { 74 NbTestSuite suite = new NbTestSuite(AnnTypeAttrTest.class); 75 return suite; 76 } 77 78 protected void setUp() { 79 clazz = (AnnotationType) Utility.findClass("org.netbeans.test.getters.AnnotationType"); 80 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 81 for (int i = 0; i < 4; i++) { 82 attribute[i] = (Attribute) clazz.getContents().get(i); 83 } 84 } 85 86 public void testAttributeIdentifier() { 87 PrintStream log = getLog(); 88 log.println("Found identifiers:"); 89 for (int i = 0; i < 4; i++) { 90 String name = attribute[i].getName(); 91 log.println("\t" + name); 92 assertEquals("Identifier differs!", name, correctIdentifiers[i]); 93 } 94 } 95 96 public void testAttributeDefaultValue() { 97 106 } 107 108 public void testAttributeDefaultValueText() { 109 PrintStream log = getLog(); 110 log.println("Found default value texts:"); 111 for (int i = 0; i < 4; i++) { 112 String defaultValueText = attribute[i].getDefaultValueText(); 113 log.println("\t" + defaultValueText); 114 assertEquals("Default Values differ!", defaultValueText, correctDefValuesText[i]); 115 } 116 } 117 118 public void testAttributeType() { 119 PrintStream log = getLog(); 120 log.println("Found types:"); 121 for (int i = 0; i < 4; i++) { 122 String type = attribute[i].getType().getName(); 123 log.println("\t" + type + "; " + correctTypes[i]); 124 assertEquals("Attribute types differ!", type, correctTypes[i]); 125 } 126 } 127 128 public void testAttributeTypeName() { 129 PrintStream log = getLog(); 130 log.println("Found type names:"); 131 for (int i = 0; i < 4; i++) { 132 String typeName = attribute[i].getTypeName().getName(); 133 log.println("\t" + typeName + "; " + correctTypeNames[i]); 134 assertEquals("Attribute type names differ!", typeName, correctTypeNames[i]); 135 } 136 } 137 138 public void testAttributeGetType() { 139 boolean fail = true; 140 Utility.beginTrans(true); 141 try { 142 Attribute attr = pkg.getAttribute().createAttribute("newA", null, 0, null, null, null, null, null); 143 Type type = attr.getType(); 144 getLog().println("Type is '" + type + "'."); 145 fail = false; 146 } 147 finally { 148 Utility.endTrans(fail); 149 } 150 } 151 152 155 public static void main(String [] args) { 156 TestRunner.run(suite()); 157 } 158 159 } 160 | Popular Tags |