1 19 20 package org.netbeans.jmi.javamodel.codegen; 21 22 import java.lang.reflect.Modifier ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.junit.NbTestSuite; 27 import org.netbeans.jmi.javamodel.JavaModelPackage; 28 import org.netbeans.jmi.javamodel.Method; 29 import org.netbeans.jmi.javamodel.Type; 30 import org.netbeans.jmi.javamodel.Import; 31 import org.netbeans.jmi.javamodel.Parameter; 32 import org.netbeans.jmi.javamodel.Resource; 33 import org.netbeans.jmi.javamodel.JavaClass; 34 import org.netbeans.jmi.javamodel.MultipartId; 35 import java.io.IOException ; 36 import java.util.Iterator ; 37 import junit.textui.TestRunner; 38 import org.netbeans.jmi.javamodel.TypeReference; 39 import org.openide.filesystems.FileStateInvalidException; 40 41 46 public class VarArgsTest extends NbTestCase { 47 48 49 public VarArgsTest() { 50 super("VarArgsTest"); 51 } 52 53 public static NbTestSuite suite() { 54 NbTestSuite suite = new NbTestSuite(VarArgsTest.class); 55 return suite; 56 } 57 58 private JavaModelPackage pkg; 59 private JavaClass clazz; 60 61 protected void setUp() { 62 clazz = Utility.findClass("org.netbeans.test.codegen.VarArgsClass"); 63 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 64 } 65 66 public void testCreation() throws IOException , FileStateInvalidException { 67 boolean fail = true; 68 Utility.beginTrans(true); 69 try { 70 MultipartId typeName = pkg.getMultipartId().createMultipartId("boolean", null, null); 74 MultipartId parType = pkg.getMultipartId().createMultipartId("String", null, null); 75 Parameter par = pkg.getParameter().createParameter( 76 "varString", null, false, parType, 0, true ); 83 Method newMethod = pkg.getMethod().createMethod( 84 "newlyCreated", null, Modifier.PRIVATE, null, null, null, "return true;", null, 92 Collections.singletonList(par), Collections.EMPTY_LIST, typeName, 0 ); 97 clazz.getFeatures().add(newMethod); 98 fail = false; 99 } finally { 100 Utility.endTrans(fail); 101 } 102 assertFile("File is not correctly generated.", 103 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/VarArgsClass.java"), 104 getGoldenFile("testCreation_VarArgsTest.pass"), 105 getWorkDir() 106 ); 107 } 108 109 public void testParAdd() throws IOException , FileStateInvalidException { 110 boolean fail = true; 111 Utility.beginTrans(true); 112 try { 113 MultipartId parType = pkg.getMultipartId().createMultipartId("Object", null, null); 116 Parameter par = pkg.getParameter().createParameter( 117 "varObject", null, false, parType, 0, true ); 124 Method method = (Method) clazz.getContents().get(0); 125 List pars = method.getParameters(); 126 pars.add(par); 127 fail = false; 128 } finally { 129 Utility.endTrans(fail); 130 } 131 assertFile("File is not correctly generated.", 132 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/VarArgsClass.java"), 133 getGoldenFile("testParAdd_VarArgsTest.pass"), 134 getWorkDir() 135 ); 136 } 137 138 public void testParChange() throws IOException , FileStateInvalidException { 139 boolean fail = true; 140 Utility.beginTrans(true); 141 try { 142 Type type = pkg.getType().resolve("long"); 146 Method method = (Method) clazz.getContents().get(1); 147 Parameter par = (Parameter) method.getParameters().get(0); 148 par.setType(type); 149 par.setName("varLong"); 150 fail = false; 151 } finally { 152 Utility.endTrans(fail); 153 } 154 assertFile("File is not correctly generated.", 155 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/VarArgsClass.java"), 156 getGoldenFile("testParChange_VarArgsTest.pass"), 157 getWorkDir() 158 ); 159 } 160 161 164 public static void main(String [] args) { 165 TestRunner.run(suite()); 166 } 167 } 168 | Popular Tags |