KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > java > generating > ConstructorElem


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
20 /*
21  * FieldElem.java
22  *
23  * Created on June 26, 2000, 9:29 AM
24  */

25
26 package org.netbeans.test.java.generating.ConstructorElem;
27
28 import org.netbeans.test.java.Common;
29 import java.lang.reflect.Modifier JavaDoc;
30 import java.util.Collections JavaDoc;
31 import org.netbeans.api.java.source.JavaSource;
32 import org.netbeans.junit.*;
33 import org.openide.filesystems.FileObject;
34 import org.openide.loaders.DataObject;
35
36 /** <B>Java Module General API Test: ConstructorElement</B>
37  * <BR><BR><I>What it tests:</I><BR>
38  * Creating and handling with ConstructorElement.
39  * Test is focused on checking of correctness of generated code.
40  * <BR><BR><I>How it works:</I><BR>
41  * New class is created using DataObject.createFromTemplate() and required constructors
42  * are created via API calls.
43  * These actions cause generating of .java code. This code is compared with supposed one.
44  * <BR><BR><I>Output:</I><BR>
45  * Generated Java code.
46  * <BR><BR><I>Possible reasons of failure:</I><BR>
47  * <U>Constructors are not inserted properly</U><BR>
48  * If there is some constructors in .diff file.
49  * <BR><BR><U>Constructors have/return bad properties</U><BR>
50  * See .diff file to get which ones
51  * <BR><BR><U>Bad indentation</U><BR>
52  * This is propably not a bug of Java Module. (Editor Bug)
53  * In .diff file could be some whitespaces.
54  * <BR><BR><U>Exception occured:</U><BR>
55  * See .log file for StackTrace
56  *
57  * @author Jan Becicka <Jan.Becicka@sun.com>
58  */

59
60
61 public class ConstructorElem extends org.netbeans.test.java.XRunner {
62     
63     public static void main(java.lang.String JavaDoc[] args) {
64         junit.textui.TestRunner.run(suite());
65     }
66     
67     public ConstructorElem() {
68         super("");
69     }
70     
71     public ConstructorElem(java.lang.String JavaDoc testName) {
72         super(testName);
73     }
74     
75     public static NbTest suite() {
76         return new NbTestSuite(ConstructorElem.class);
77     }
78     
79     /** "body" of this TestCase
80      * @param o SourceElement - target for generating
81      * @param log log is used for logging StackTraces
82      * @throws Exception
83      * @return true if test passed
84      * false if failed
85      */

86     public boolean go(Object JavaDoc o, java.io.PrintWriter JavaDoc log) throws Exception JavaDoc {
87         boolean passed = true;
88         FileObject fo = (FileObject) o;
89         JavaSource js = JavaSource.forFileObject(fo);
90         Common.removeConstructors(js);
91         Common.addConstructor(js, Collections.EMPTY_MAP);
92         Common.addConstructor(js, Common.PARS1);
93         Common.addConstructor(js, Common.PARS2);
94         Common.addConstructor(js, Common.PARS3);
95         return true;
96     }
97     
98     /**
99      */

100     protected void setUp() {
101         super.setUp();
102         name = "JavaTestSourceConstructorElem";
103         packageName = "org.netbeans.test.java.testsources";
104     }
105     
106 }
107
Popular Tags