1 19 20 package org.netbeans.jmi.javamodel.codegen; 21 22 import java.io.IOException ; 23 import java.lang.reflect.Modifier ; 24 import java.util.Collections ; 25 import org.netbeans.jmi.javamodel.*; 26 import org.netbeans.junit.*; 27 import org.openide.filesystems.FileStateInvalidException; 28 29 33 public class SuperClassTest extends NbTestCase { 34 35 JavaClass clazz; 36 String cbn; 37 JavaModelPackage pkg; 38 39 40 public SuperClassTest() { 41 super("SuperClassTest"); 42 } 43 44 protected void setUp() { 45 clazz = Utility.findClass("org.netbeans.test.codegen.SuperClassTest"); 46 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 47 } 48 49 public static NbTestSuite suite() { 50 NbTestSuite suite = new NbTestSuite(SuperClassTest.class); 51 return suite; 52 } 53 54 public void testAddClass() throws IOException , FileStateInvalidException { 55 boolean fail = true; 56 Utility.beginTrans(true); 57 try { 58 MultipartId multi = pkg.getMultipartId().createMultipartId("SecondInnerClass", null, null); 59 JavaClass innerClass = pkg.getJavaClass().createJavaClass( 60 "ThirdInnerClass", null, Modifier.STATIC, null, null, Collections.EMPTY_LIST, multi, null, null 69 ); 70 clazz.getContents().add(innerClass); 71 fail = false; 72 } finally { 73 Utility.endTrans(fail); 74 } 75 assertFile("File is not correctly generated.", 76 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"), 77 getGoldenFile("testAddClass_SuperClassTest.pass"), 78 getWorkDir() 79 ); 80 } 81 82 public void testChange() throws IOException , FileStateInvalidException { 83 boolean fail = true; 84 Utility.beginTrans(true); 85 try { 86 JavaClass inner = (JavaClass) clazz.getContents().get(2); 87 MultipartId id = pkg.getMultipartId().createMultipartId("SuperClassTest", null, null); 88 inner.setSuperClass((JavaClass) clazz.getContents().get(1)); 89 inner.setSuperClassName(id); 90 fail = false; 91 } finally { 92 Utility.endTrans(fail); 93 } 94 assertFile("File is not correctly generated.", 95 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"), 96 getGoldenFile("testChange_SuperClassTest.pass"), 97 getWorkDir() 98 ); 99 } 100 101 public void testAddSuper() throws FileStateInvalidException, IOException { 102 boolean fail = true; 103 Utility.beginTrans(true); 104 try { 105 JavaClass inner = (JavaClass) clazz.getContents().get(1); 106 MultipartId id = pkg.getMultipartId().createMultipartId("NoExt", null, null); 107 inner.setSuperClassName(id); 108 inner.setSuperClass(clazz); 109 fail = false; 110 } finally { 111 Utility.endTrans(fail); 112 } 113 assertFile("File is not correctly generated.", 114 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"), 115 getGoldenFile("testAddSuper_SuperClassTest.pass"), 116 getWorkDir() 117 ); 118 } 119 120 121 124 public static void main(String [] args) { 125 } 127 128 } 129 | Popular Tags |