1 19 package org.netbeans.jmi.javamodel.codegen; 20 21 import java.lang.reflect.Modifier ; 22 import java.util.Iterator ; 23 import junit.textui.TestRunner; 24 import org.netbeans.jmi.javamodel.Feature; 25 import org.netbeans.jmi.javamodel.Field; 26 import org.netbeans.jmi.javamodel.FieldGroup; 27 import org.netbeans.jmi.javamodel.JavaClass; 28 import org.netbeans.jmi.javamodel.JavaModelPackage; 29 import org.netbeans.jmi.javamodel.TypeReference; 30 import org.netbeans.junit.NbTestCase; 31 import org.netbeans.junit.NbTestSuite; 32 import org.netbeans.modules.javacore.jmiimpl.javamodel.TypeReferenceImpl; 33 import org.openide.filesystems.FileStateInvalidException; 34 35 39 public class FieldTest2 extends NbTestCase { 40 41 42 public FieldTest2() { 43 super("FieldTest2"); 44 } 45 46 public static NbTestSuite suite() { 47 NbTestSuite suite = new NbTestSuite(FieldTest2.class); 48 return suite; 49 } 50 51 JavaClass clazz; 52 JavaModelPackage pkg; 53 54 protected void setUp() { 55 clazz = Utility.findClass("org.netbeans.test.codegen.FieldTest2"); 56 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 57 } 58 59 62 public void testMoveField() throws java.io.IOException , FileStateInvalidException { 63 boolean fail = true; 64 Utility.beginTrans(true); 65 try { 66 Field nerudova = null; 67 for (Iterator fIt = clazz.getContents().iterator(); fIt.hasNext(); ) { 68 Object feature = fIt.next(); 69 if (feature instanceof FieldGroup) { 70 FieldGroup group = (FieldGroup) feature; 71 nerudova = (Field) group.getFields().remove(2); 72 nerudova.setTypeName((TypeReference) ((TypeReferenceImpl) group.getTypeName()).duplicate()); 73 nerudova.setModifiers(Modifier.PRIVATE); 74 } 75 } 76 clazz.getFeatures().add(nerudova); 77 fail = false; 78 } 79 finally { 80 Utility.endTrans(fail); 81 } 82 assertFile("File is not correctly generated.", 83 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/FieldTest2.java"), 84 getGoldenFile("FieldTest2.pass"), 85 getWorkDir() 86 ); 87 } 88 89 92 public static void main(String [] args) { 93 TestRunner.run(suite()); 94 } 95 96 } 97 | Popular Tags |