1 19 package org.netbeans.jmi.javamodel.codegen; 20 21 import java.lang.reflect.Modifier ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import junit.textui.TestRunner; 26 import org.netbeans.jmi.javamodel.Expression; 27 import org.netbeans.jmi.javamodel.Field; 28 import org.netbeans.jmi.javamodel.FieldGroup; 29 import org.netbeans.jmi.javamodel.ForStatement; 30 import org.netbeans.jmi.javamodel.JavaClass; 31 import org.netbeans.jmi.javamodel.JavaModelPackage; 32 import org.netbeans.jmi.javamodel.LocalVarDeclaration; 33 import org.netbeans.jmi.javamodel.LocalVariable; 34 import org.netbeans.jmi.javamodel.Method; 35 import org.netbeans.jmi.javamodel.MethodClass; 36 import org.netbeans.jmi.javamodel.MultipartId; 37 import org.netbeans.jmi.javamodel.OperatorEnum; 38 import org.netbeans.jmi.javamodel.StatementBlock; 39 import org.netbeans.jmi.javamodel.UnaryExpression; 40 import org.netbeans.junit.NbTestCase; 41 import org.netbeans.junit.NbTestSuite; 42 import org.openide.filesystems.FileStateInvalidException; 43 44 48 public class GroupTest extends NbTestCase { 49 50 51 public GroupTest() { 52 super("GroupTest"); 53 } 54 55 public static NbTestSuite suite() { 56 NbTestSuite suite = new NbTestSuite(GroupTest.class); 57 return suite; 58 } 59 60 JavaClass clazz; 61 JavaModelPackage pkg; 62 63 protected void setUp() { 64 clazz = Utility.findClass("org.netbeans.test.codegen.GroupTestClass"); 65 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 66 } 67 68 71 public void testGroup() throws java.io.IOException , FileStateInvalidException { 72 boolean fail = true; 73 Utility.beginTrans(true); 74 try { 75 int i = 0; 76 for (Iterator fIt = clazz.getContents().iterator(); fIt.hasNext(); ) { 77 i++; 78 FieldGroup fieldGroup = (FieldGroup) fIt.next(); 79 Field fieldToRemove = null; 80 for (Iterator fieldsIt = fieldGroup.getFields().iterator(); fieldsIt.hasNext(); ) { 81 Field f = (Field) fieldsIt.next(); 82 String fieldName = f.getName(); 83 if ("b".equals(fieldName)) { 84 f.setName("bingo"); 85 } else if ("sun".equals(fieldName)) { 86 f.setInitialValueText("\"does not have notebooks!\""); 87 } else if ("ibm".equals(fieldName)) { 88 f.setInitialValueText("\"Thinkpad\""); 89 } else if ("coca".equals(fieldName)) { 90 fieldToRemove = f; 91 } else if ("rc".equals(fieldName)) { 92 f.setInitialValueText(null); 93 } 94 } 95 fieldGroup.getFields().remove(fieldToRemove); 96 } 97 fail = false; 98 } 99 finally { 100 Utility.endTrans(fail); 101 } 102 assertFile("File is not correctly generated.", 103 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/GroupTestClass.java"), 104 getGoldenFile("GroupTestClass.pass"), 105 getWorkDir() 106 ); 107 } 108 109 110 113 public static void main(String [] args) { 114 TestRunner.run(suite()); 115 } 116 117 } 118 | Popular Tags |