1 19 package org.netbeans.jmi.javamodel.codegen.indent; 20 21 import java.lang.reflect.Modifier ; 22 import java.util.Collections ; 23 import org.netbeans.jmi.javamodel.JavaClass; 24 import org.netbeans.jmi.javamodel.JavaModelPackage; 25 import org.netbeans.jmi.javamodel.Method; 26 import org.netbeans.jmi.javamodel.codegen.Utility; 27 import org.netbeans.junit.NbTestCase; 28 import org.netbeans.junit.NbTestSuite; 29 import org.openide.filesystems.FileStateInvalidException; 30 31 36 public class MethodBodyTextTest extends NbTestCase { 37 38 JavaClass clazz; 39 JavaModelPackage pkg; 40 41 42 public MethodBodyTextTest() { 43 super("MethodBodyTextTest"); 44 } 45 46 public static NbTestSuite suite() { 47 NbTestSuite suite = new NbTestSuite(MethodBodyTextTest.class); 48 return suite; 49 } 50 51 protected void setUp() { 52 clazz = (JavaClass) Utility.findClass("org.netbeans.test.codegen.indent.MethodBodyText"); 53 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 54 } 55 56 public void testSetBodyText() throws java.io.IOException , FileStateInvalidException { 57 boolean fail = true; 58 Utility.beginTrans(true); 59 try { 60 Method m = (Method) clazz.getContents().get(0); 61 m.setBodyText("\n\n// nothing\n"); 62 fail = false; 63 } 64 finally { 65 Utility.endTrans(fail); 66 } 67 assertFile("File is not correctly generated.", 68 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/MethodBodyText.java"), 69 getGoldenFile("testSetBodyText_MethodBodyTextTest.pass"), 70 getWorkDir() 71 ); 72 } 73 74 public void testCreateWithBodyText() throws java.io.IOException , FileStateInvalidException { 75 boolean fail = true; 76 Utility.beginTrans(true); 77 StringBuffer body = new StringBuffer (); 78 body.append("\n// TODO add your own implementation\n\n\n"); 79 try { 80 Method m = pkg.getMethod().createMethod( 81 "method2", 82 Collections.EMPTY_LIST, 83 Modifier.PUBLIC, 84 null, null, null, body.toString(), Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, pkg.getMultipartId().createMultipartId("void", null, null), 0); 93 94 clazz.getContents().add(m); 95 fail = false; 96 } 97 finally { 98 Utility.endTrans(fail); 99 } 100 assertFile("File is not correctly generated.", 101 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/MethodBodyText.java"), 102 getGoldenFile("testCreateWithBodyText_MethodBodyTextTest.pass"), 103 getWorkDir() 104 ); 105 } 106 107 public void testModifyBodyText() throws java.io.IOException , FileStateInvalidException { 108 boolean fail = true; 109 Utility.beginTrans(true); 110 try { 111 Method m = (Method) clazz.getContents().get(1); 112 m.setBodyText(m.getBodyText() + "// TODO no new lines around"); 113 fail = false; 114 } 115 finally { 116 Utility.endTrans(fail); 117 } 118 assertFile("File is not correctly generated.", 119 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/indent/MethodBodyText.java"), 120 getGoldenFile("testModifyBodyText_MethodBodyTextTest.pass"), 121 getWorkDir() 122 ); 123 } 124 } 125 | Popular Tags |