1 19 package org.netbeans.jmi.javamodel.codegen; 20 21 import org.netbeans.junit.NbTestCase; 22 import org.netbeans.junit.NbTestSuite; 23 import org.netbeans.jmi.javamodel.JavaModelPackage; 24 import org.netbeans.jmi.javamodel.Import; 25 import org.netbeans.jmi.javamodel.Resource; 26 import org.netbeans.jmi.javamodel.JavaClass; 27 import java.io.IOException ; 28 import java.util.Iterator ; 29 import junit.textui.TestRunner; 30 import org.netbeans.jmi.javamodel.Feature; 31 import org.openide.filesystems.FileStateInvalidException; 32 33 38 public class JavaDocTest extends NbTestCase { 39 40 JavaModelPackage pkg; 41 JavaClass clazz; 42 43 44 public JavaDocTest() { 45 super("JavaDocTest"); 46 } 47 48 public static NbTestSuite suite() { 49 NbTestSuite suite = new NbTestSuite(JavaDocTest.class); 50 return suite; 51 } 52 53 protected void setUp() { 54 clazz = Utility.findClass("org.netbeans.test.codegen.JavaDocTestClass"); 55 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 56 } 57 58 public void testAddJavaDocText() throws IOException , FileStateInvalidException { 59 boolean fail = true; 60 Utility.beginTrans(true); 61 try { 62 ((Feature) clazz.getContents().get(0)).setJavadocText("JavaDoc for the firstMethod."); 63 fail = false; 64 } finally { 65 Utility.endTrans(fail); 66 } 67 assertFile("File is not correctly generated.", 68 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/JavaDocTestClass.java"), 69 getGoldenFile("testAddJavaDocText_JavaDocTest.pass"), 70 getWorkDir() 71 ); 72 } 73 74 public void testChangeJavaDocText() throws IOException , FileStateInvalidException { 75 boolean fail = true; 76 Utility.beginTrans(true); 77 try { 78 ((Feature) clazz.getContents().get(1)).setJavadocText("Javadoc to be changed.\nTwo line comment."); 79 fail = false; 80 } finally { 81 Utility.endTrans(fail); 82 } 83 assertFile("File is not correctly generated.", 84 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/JavaDocTestClass.java"), 85 getGoldenFile("testChangeJavaDocText_JavaDocTest.pass"), 86 getWorkDir() 87 ); 88 } 89 90 public void testAddJavaDocText2() throws IOException , FileStateInvalidException { 91 boolean fail = true; 92 Utility.beginTrans(true); 93 try { 94 clazz.setJavadocText("This is TestFile\n@author NoBody"); 95 fail = false; 96 } finally { 97 Utility.endTrans(fail); 98 } 99 assertFile("File is not correctly generated.", 100 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/JavaDocTestClass.java"), 101 getGoldenFile("testAddJavaDocText2_JavaDocTest.pass"), 102 getWorkDir() 103 ); 104 } 105 106 public void testRemoveJavaDocText() throws IOException , FileStateInvalidException { 107 boolean fail = true; 108 Utility.beginTrans(true); 109 try { 110 clazz.setJavadocText(null); 111 fail = false; 112 } finally { 113 Utility.endTrans(fail); 114 } 115 assertFile("File is not correctly generated.", 116 Utility.getFile(getDataDir(), "org/netbeans/test/codegen/JavaDocTestClass.java"), 117 getGoldenFile("testRemoveJavaDocText_JavaDocTest.pass"), 118 getWorkDir() 119 ); 120 } 121 122 public void testAddJavaDocText3() throws IOException , FileStateInvalidException { 123 boolean fail = true; 124 Utility.beginTrans(true); 125 try { 126 clazz.setJavadocText("This is TestFile\n@author NoBody"); 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/JavaDocTestClass.java"), 133 getGoldenFile("testAddJavaDocText2_JavaDocTest.pass"), 134 getWorkDir() 135 ); 136 } 137 138 141 public static void main(String [] args) { 142 TestRunner.run(suite()); 143 } 144 145 } 146 | Popular Tags |