KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > getters > JavaDocTextTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.jmi.javamodel.getters;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
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 /*
34  *
35  * @author Pavel Flaska
36  */

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 JavaDoc[][] 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 JavaDoc text = javadoc.getText();
89             assertEquals(" Nothing interesting.\n", text);
90             List JavaDoc/*TagValue*/ tags = javadoc.getTags();
91             getLog().println(text);
92             int i = 0;
93             for (Iterator JavaDoc 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 JavaDoc 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     /** Use for execution inside IDE */
121     public static void main(java.lang.String JavaDoc[] args) {
122         TestRunner.run(suite());
123     }
124     
125     String JavaDoc[] 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