KickJava   Java API By Example, From Geeks To Geeks.

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


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.InitializerElem;
27
28 import org.netbeans.test.java.Common;
29 import java.lang.reflect.Modifier JavaDoc;
30 import org.netbeans.api.java.source.JavaSource;
31 import org.netbeans.junit.*;
32 import org.openide.filesystems.FileObject;
33
34 /** <B>Java Module General API Test: InitializerElement</B>
35  * <BR><BR><I>What it tests:</I><BR>
36  * Creating and handling with InitializerElement.
37  * Test is focused on checking of correctness of generated code.
38  * <BR><BR><I>How it works:</I><BR>
39  * New class is created using DataObject.createFromTemplate() and also some InitializerElements are created.
40  * These are customized using setters and then added using ClassElement.addInitializer() into ClassElement.
41  * These actions cause generating of .java code. This code is compared with supposed one.
42  * <BR><BR><I>Output:</I><BR>
43  * Generated Java code.
44  * <BR><BR><I>Possible reasons of failure:</I><BR>
45  * <U>Initialzers are not inserted properly:</U><BR>
46  * If there are some Initialzers in .diff file.
47  * <BR><BR><U>Initializers have/return bad properies</U><BR>
48  * See .diff file to get which ones
49  * <BR><BR><U>Bad indentation</U><BR>
50  * This is probably not a bug of Java Module. (->Editor Bug)
51  * In .diff file could be some whitespaces.
52  * <BR><BR><U>Exception occured:</U><BR>
53  * See .log file for StackTrace
54  *
55  *
56  * @author Jan Becicka <Jan.Becicka@sun.com>
57  */

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

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

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