1 19 20 package org.netbeans.jmi.javamodel.codegen; 21 22 import java.util.Collections ; 23 import junit.textui.TestRunner; 24 import org.netbeans.jmi.javamodel.Expression; 25 import org.netbeans.jmi.javamodel.ForEachStatement; 26 27 import org.netbeans.jmi.javamodel.JavaClass; 28 import org.netbeans.jmi.javamodel.JavaModelPackage; 29 import org.netbeans.junit.NbTestCase; 30 import org.netbeans.junit.NbTestSuite; 31 import org.netbeans.jmi.javamodel.Method; 32 import org.netbeans.jmi.javamodel.MethodInvocation; 33 import org.netbeans.jmi.javamodel.MultipartId; 34 import org.netbeans.jmi.javamodel.Parameter; 35 import org.netbeans.jmi.javamodel.Statement; 36 import org.netbeans.jmi.javamodel.StatementBlock; 37 import org.netbeans.jmi.javamodel.TypeReference; 38 import org.openide.filesystems.AbstractFileSystem.List; 39 import org.openide.filesystems.FileStateInvalidException; 40 41 45 public class ForEachTest1 extends NbTestCase { 46 47 48 public ForEachTest1() { 49 super("ForEachTest1"); 50 } 51 52 public static NbTestSuite suite() { 53 NbTestSuite suite = new NbTestSuite(ForEachTest1.class); 54 return suite; 55 } 56 57 Method method; 58 JavaModelPackage pkg; 59 60 protected void setUp() { 61 JavaClass clazz = Utility.findClass("org.netbeans.test.codegen.ForEachTest1"); 62 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 63 method = (Method) clazz.getContents().iterator().next(); 64 } 65 66 public void testForCreation() throws java.io.IOException , FileStateInvalidException { 67 boolean fail = true; 68 Utility.beginTrans(true); 69 try { 70 TypeReference typeRef = pkg.getMultipartId().createMultipartId("String", null, null); 72 Parameter parameter = pkg.getParameter().createParameter("s", null, false, typeRef, 0, false); 73 Expression iterable = pkg.getMultipartId().createMultipartId("c", null, null); 75 Expression par = pkg.getMultipartId().createMultipartId("s", null, null); 77 MultipartId parent = pkg.getMultipartId().createMultipartId("System.out", null, null); 78 MethodInvocation invocation = pkg.getMethodInvocation().createMethodInvocation("println", Collections.singletonList(par), parent, false); 79 Statement statement = pkg.getExpressionStatement().createExpressionStatement(invocation); 80 StatementBlock forBody = pkg.getStatementBlock().createStatementBlock(); 82 forBody.getStatements().add(statement); 83 ForEachStatement fes = pkg.getForEachStatement().createForEachStatement(forBody, parameter, iterable); 87 method.getBody().getStatements().add(fes); 89 fail = false; 90 } finally { 91 Utility.endTrans(fail); 92 } 93 assertFile("File is not correctly generated.", 94 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/ForEachTest1.java"), 95 getGoldenFile("testForCreation_ForEachTest1.pass"), 96 getWorkDir() 97 ); 98 } 99 102 public static void main(String [] args) { 103 TestRunner.run(suite()); 104 } 105 } 106 | Popular Tags |