KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > jmi > javamodel > codegen > JavaDocTest


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.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 JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import junit.textui.TestRunner;
30 import org.netbeans.jmi.javamodel.Feature;
31 import org.openide.filesystems.FileStateInvalidException;
32
33 /**
34  * Tests the JavaDocText code-generation.
35  *
36  * @author Pavel Flaska
37  */

38 public class JavaDocTest extends NbTestCase {
39     
40     JavaModelPackage pkg;
41     JavaClass clazz;
42     
43     /** Creates a new instance of JavaDocTest */
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 JavaDoc, 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 JavaDoc, 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 JavaDoc, 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 JavaDoc, 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 JavaDoc, 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     /**
139      * @param args the command line arguments
140      */

141     public static void main(String JavaDoc[] args) {
142         TestRunner.run(suite());
143     }
144     
145 }
146
Popular Tags