1 19 20 package org.netbeans.jmi.javamodel.codegen; 21 22 import org.netbeans.junit.NbTestSuite; 23 import org.netbeans.junit.NbTestCase; 24 import org.netbeans.jmi.javamodel.*; 25 import org.openide.filesystems.FileStateInvalidException; 26 import junit.textui.TestRunner; 27 import java.io.IOException ; 28 import java.util.Arrays ; 29 30 33 public class GenericsTest extends NbTestCase { 34 public GenericsTest() { 35 super("GenericsTest"); 36 } 37 38 public static NbTestSuite suite() { 39 NbTestSuite suite = new NbTestSuite(GenericsTest.class); 40 return suite; 41 } 42 43 JavaClass clazz; 44 JavaModelPackage pkg; 45 46 protected void setUp() { 47 clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.Generics"); 48 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 49 } 50 51 public void testAddBound() throws java.io.IOException , FileStateInvalidException { 52 boolean fail = true; 53 Utility.beginTrans(true); 54 try { 55 TypeParameter tp = (TypeParameter) clazz.getTypeParameters().get(0); 56 tp.getInterfaceNames().add(pkg.getMultipartId().createMultipartId("List", null, null)); 57 fail = false; 58 } 59 finally { 60 Utility.endTrans(fail); 61 } 62 assertFile("File is not correctly generated.", 63 getGoldenFile("Generics.pass"), 64 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/Generics.java"), 65 getWorkDir() 66 ); 67 } 68 69 public void testAddTypeParamMethod() throws IOException , FileStateInvalidException { 70 JavaClass cls = (JavaClass) Utility.findClass("org.netbeans.test.codegen.GenericMethod"); 71 boolean fail = true; 72 Utility.beginTrans(true); 73 try { 74 TypeParameter tp = pkg.getTypeParameter().createTypeParameter("Y", null, 0, null, null, null, null, Arrays.asList(new Object [] {pkg.getMultipartId().createMultipartId("Collection", null, null)}), null); 75 Method m = (Method) cls.getContents().get(0); 76 m.getTypeParameters().add(tp); 77 fail = false; 78 } 79 finally { 80 Utility.endTrans(fail); 81 } 82 assertFile("File is not correctly generated.", 83 getGoldenFile("GenericMethod.pass"), 84 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/GenericMethod.java"), 85 getWorkDir() 86 ); 87 } 88 89 92 public static void main(String [] args) { 93 TestRunner.run(suite()); 94 } 95 96 } 97 | Popular Tags |