KickJava   Java API By Example, From Geeks To Geeks.

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


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.SourceElem;
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: SourceElement</B>
35  * <BR><BR><I>What it tests:</I><BR>
36  * Creating and handling with SourceElement.
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().
40  * This SourceElement is then customized using setters. Some classes are inserted.
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  * <BR><BR><U>SourceElement have/return bad properties</U><BR>
46  * See .diff file to get which ones
47  * <BR><BR><U>Bad indentation</U><BR>
48  * This is probably not a bug of Java Module. (Editor Bug)
49  * In .diff file could be some whitespaces.
50  * <BR><BR><U>Exception occured:</U><BR>
51  * See .log file for StackTrace
52  *
53  * @author Jan Becicka <Jan.Becicka@sun.com>
54  */

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

82     public boolean go(Object JavaDoc o, java.io.PrintWriter JavaDoc log) throws Exception JavaDoc {
83         
84 // org.openide.src.SourceElement source = (org.openide.src.SourceElement) o;
85
boolean passed = true;
86         FileObject fo = (FileObject) o;
87         JavaSource js = JavaSource.forFileObject(fo);
88         Common.addImport(js, "java.awt.image.RGBImageFilter", false);
89         Common.addImport(js, "javax.swing.event.HyperlinkEvent", false);
90         Common.addImport(js, "java.awt.Color.BLACK", true);
91         Common.setPackage(js, "newpack");
92         Common.addTopLevelClass(js);
93         return passed;
94     }
95     
96     /**
97      */

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