KickJava   Java API By Example, From Geeks To Geeks.

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


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.MethodElem;
27
28 import org.netbeans.test.java.Common;
29 import java.util.EnumSet JavaDoc;
30 import javax.lang.model.element.Modifier;
31 import org.netbeans.api.java.source.JavaSource;
32 import org.netbeans.junit.*;
33 import org.openide.filesystems.FileObject;
34
35 /** <B>Java Module General API Test: MethodElement</B>
36  * <BR><BR><I>What it tests:</I><BR>
37  * Creating and handling with MethodElement.
38  * Test is focused on checking of correctness of generated code.
39  * <BR><BR><I>How it works:</I><BR>
40  * New class is created using DataObject.createFromTemplate() and also some MethodElements are created.
41  * These are customized using setters and then added using ClassElement.addMethod() 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>Methods are not inserted properly</U><BR>
47  * If there are some Interfaces in .diff file.
48  * <BR><BR><U>Methods have/return bad properies</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><I>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 MethodElem 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 MethodElem() {
67         super("");
68     }
69     
70     public MethodElem(java.lang.String JavaDoc testName) {
71         super(testName);
72     }
73     
74     public static NbTest suite() {
75         return new NbTestSuite(MethodElem.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         // org.openide.src.ClassElement clazz = ((org.openide.src.SourceElement) o).getClasses()[0];
88
boolean passed = true;
89         FileObject fo = (FileObject) o;
90         JavaSource js = JavaSource.forFileObject(fo);
91         
92         Common.addMethod(js, "method1",Common.PARS1,"void", EnumSet.of(Modifier.PUBLIC,Modifier.STATIC));
93         Common.addMethod(js, "method1",Common.PARS2,"int", EnumSet.of(Modifier.PRIVATE,Modifier.SYNCHRONIZED));
94         Common.addMethod(js, "method1",Common.PARS3,"float", EnumSet.of(Modifier.PRIVATE,Modifier.FINAL));
95         Common.addMethod(js, "method2",Common.PARS1,"double", EnumSet.of(Modifier.PUBLIC,Modifier.STATIC));
96         Common.addMethod(js, "method2",Common.PARS2,"boolean", EnumSet.of(Modifier.PUBLIC,Modifier.STATIC));
97         Common.addMethod(js, "method2",Common.PARS3,"void", EnumSet.of(Modifier.PUBLIC,Modifier.STATIC));
98         
99         return passed;
100     }
101     
102     /**
103      */

104     protected void setUp() {
105         super.setUp();
106         name = "JavaTestSourceMethodElem";
107         packageName = "org.netbeans.test.java.testsources";
108     }
109     
110 }
111
Popular Tags