1 19 package org.netbeans.jmi.javamodel.codegen; 20 21 import java.io.IOException ; 22 import java.lang.reflect.Modifier ; 23 import org.netbeans.jmi.javamodel.ClassDefinition; 24 import org.netbeans.jmi.javamodel.ExpressionStatement; 25 import org.netbeans.jmi.javamodel.JavaClass; 26 import org.netbeans.jmi.javamodel.JavaModelPackage; 27 import org.netbeans.jmi.javamodel.Method; 28 import org.netbeans.jmi.javamodel.NewClassExpression; 29 import org.netbeans.jmi.javamodel.PrimitiveTypeKindEnum; 30 import org.netbeans.junit.NbTestCase; 31 import org.netbeans.junit.NbTestSuite; 32 import org.openide.filesystems.FileStateInvalidException; 33 34 38 public class NewClassWithAnnTest extends NbTestCase { 39 40 41 public NewClassWithAnnTest() { 42 super("NewClassWithAnnTest"); 43 } 44 45 public static NbTestSuite suite() { 46 NbTestSuite suite = new NbTestSuite(NewClassWithAnnTest.class); 47 return suite; 48 } 49 50 JavaClass clazz; 51 JavaModelPackage pkg; 52 53 protected void setUp() { 54 clazz = Utility.findClass("org.netbeans.test.codegen.NewClassWithAnn"); 55 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 56 } 57 58 public void testAddBody() throws IOException , FileStateInvalidException { 59 boolean fail = true; 60 Utility.beginTrans(true); 61 try { 62 Method m = (Method) clazz.getContents().get(0); 63 ExpressionStatement st = (ExpressionStatement) m.getBody().getStatements().get(0); 64 NewClassExpression nce = (NewClassExpression) st.getExpression(); 65 ClassDefinition cd = pkg.getClassDefinition().createClassDefinition(); 66 cd.setSuperClassName(pkg.getMultipartId().createMultipartId("java.lang.Runnable", null, null)); 67 Method m1 = pkg.getMethod().createMethod("run", null, Modifier.PUBLIC, null, null, 68 null, null, null, null, null, pkg.getMultipartId().createMultipartId("void", null, null), 0); 69 cd.getContents().add(m1); 70 nce.setClassDefinition(cd); 71 fail = false; 72 } 73 finally { 74 Utility.endTrans(fail); 75 } 76 assertFile("File is not correctly generated.", 77 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/NewClassWithAnn.java"), 78 getGoldenFile("testAddBody_NewClassWithAnn.pass"), 79 getWorkDir() 80 ); 81 } 82 } 83 | Popular Tags |