KickJava   Java API By Example, From Geeks To Geeks.

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


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

58
59
60 public class FieldElem 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 FieldElem() {
67         super("");
68     }
69     
70     public FieldElem(java.lang.String JavaDoc testName) {
71         super(testName);
72     }
73     
74     public static NbTest suite() {
75         return new NbTestSuite(FieldElem.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         //let's add some fields newField1 .. newField4
91
int i=1;
92         EnumSet JavaDoc<Modifier> set = EnumSet.of(Modifier.PUBLIC,Modifier.STATIC);
93         Common.addField(js,Common.getFieldName(i++), set, "boolean");
94         
95         set = EnumSet.of(Modifier.PRIVATE,Modifier.STATIC);
96         Common.addField(js,Common.getFieldName(i++), set, "int");
97         
98         set = EnumSet.of(Modifier.PROTECTED);
99         Common.addField(js,Common.getFieldName(i++), set, "boolean");
100         
101         set = EnumSet.of(Modifier.SYNCHRONIZED,Modifier.PUBLIC);
102         Common.addField(js,Common.getFieldName(i++), set, "float");
103         
104         set = EnumSet.of(Modifier.FINAL,Modifier.PUBLIC,Modifier.STATIC);
105         Common.addField(js,Common.getFieldName(i++), set, "String");
106         return true;
107     }
108     
109     /**
110      */

111     protected void setUp() {
112         super.setUp();
113         name = "JavaTestSourceFieldElem";
114         packageName = "org.netbeans.test.java.testsources";
115     }
116 }
117
Popular Tags