1 19 package org.netbeans.jmi.javamodel.getters; 20 21 import java.util.Iterator ; 22 import java.util.List ; 23 import junit.textui.TestRunner; 24 import org.netbeans.jmi.javamodel.Feature; 25 import org.netbeans.jmi.javamodel.codegen.Utility; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.jmi.javamodel.JavaClass; 28 import org.netbeans.jmi.javamodel.JavaDoc; 29 import org.netbeans.jmi.javamodel.JavaModelPackage; 30 import org.netbeans.jmi.javamodel.TagValue; 31 import org.netbeans.junit.NbTestSuite; 32 33 37 public class JavaDocTextTest extends NbTestCase { 38 39 JavaClass clazz; 40 JavaModelPackage pkg; 41 42 public JavaDocTextTest() { 43 super("JavaDocTextTest"); 44 } 45 46 public static NbTestSuite suite() { 47 NbTestSuite suite = new NbTestSuite(JavaDocTextTest.class); 48 return suite; 49 } 50 51 protected void setUp() { 52 clazz = (JavaClass) Utility.findClass("org.netbeans.test.getters.JavaDocText"); 53 pkg = (JavaModelPackage) clazz.refImmediatePackage(); 54 } 55 56 public void testGet1() { 57 testText(2); 58 } 59 60 public void testGet2() { 61 testText(3); 62 } 63 64 public void testGet3() { 65 testText(4); 66 } 67 68 public void testGet4() { 69 testText(5); 70 } 71 72 public void testGetDoc1() { 73 String [][] result = { 74 { "@param", "c cecko" }, 75 { "@param", "ax aikso" }, 76 { "@param", "b becko" }, 77 { "@author", "Lee Boynton" }, 78 { "@author", "Arthur van Hoff" }, 79 { "@version", "unknown" }, 80 { "@see", "java.lang.Object#toString()" }, 81 { "@see", "java.nio.charset.Charset" }, 82 { "@since", "1895" } 83 }; 84 Utility.beginTrans(false); 85 try { 86 Feature f = (Feature) clazz.getContents().get(6); 87 JavaDoc javadoc = f.getJavadoc(); 88 String text = javadoc.getText(); 89 assertEquals(" Nothing interesting.\n", text); 90 List tags = javadoc.getTags(); 91 getLog().println(text); 92 int i = 0; 93 for (Iterator it = tags.iterator(); it.hasNext(); i++) { 94 TagValue tag = (TagValue) it.next(); 95 getLog().print(tag.getDefinition().getName() + "; "); 96 getLog().println(tag.getValue()); 97 assertEquals(result[i][0], tag.getDefinition().getName()); 98 assertEquals(result[i][1], tag.getValue()); 99 } 100 } 101 finally { 102 Utility.endTrans(); 103 } 104 } 105 106 private void testText(int index) { 107 Utility.beginTrans(false); 108 try { 109 Feature f = (Feature) clazz.getContents().get(index); 110 String javadocText = f.getJavadocText(); 111 getLog().println("Obtained text '" + javadocText + "'"); 112 getLog().println("Expected text '" + resultsText[index] + "'"); 113 assertEquals(resultsText[index], javadocText); 114 } 115 finally { 116 Utility.endTrans(); 117 } 118 } 119 120 121 public static void main(java.lang.String [] args) { 122 TestRunner.run(suite()); 123 } 124 125 String [] resultsText = { 126 "", 127 "", 128 " Creates a new instance of JavaDocText ", 129 " Constructor with one parameter.\n\n @param charles karluv parameter\n", 130 " Methoda.\n \n @param a letter\n @param text does not matter\n @return no comment\n", 131 " In this javadoc text, there are more new lines,\n missing asterisks at the beginning, html tags\n" + 132 "<pre>\n Preformatted.\n</pre>\n and many other things.\n Not only that, but also more new lines" + 133 " at the\n end of the comment are tested.\n\n\n" 134 }; 135 136 } 137 | Popular Tags |