001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * FieldElem.java
044: *
045: * Created on June 26, 2000, 9:29 AM
046: */
047:
048: package org.netbeans.test.java.generating.MethodElem;
049:
050: import org.netbeans.test.java.Common;
051: import java.util.EnumSet;
052: import javax.lang.model.element.Modifier;
053: import org.netbeans.api.java.source.JavaSource;
054: import org.netbeans.junit.*;
055: import org.openide.filesystems.FileObject;
056:
057: /** <B>Java Module General API Test: MethodElement</B>
058: * <BR><BR><I>What it tests:</I><BR>
059: * Creating and handling with MethodElement.
060: * Test is focused on checking of correctness of generated code.
061: * <BR><BR><I>How it works:</I><BR>
062: * New class is created using DataObject.createFromTemplate() and also some MethodElements are created.
063: * These are customized using setters and then added using ClassElement.addMethod() into ClassElement.
064: * These actions cause generating of .java code. This code is compared with supposed one.
065: * <BR><BR><I>Output:</I><BR>
066: * Generated Java code.
067: * <BR><BR><I>Possible reasons of failure:</I><BR>
068: * <U>Methods are not inserted properly</U><BR>
069: * If there are some Interfaces in .diff file.
070: * <BR><BR><U>Methods have/return bad properies</U><BR>
071: * See .diff file to get which ones
072: * <BR><BR><U>Bad indentation</U><BR>
073: * This is probably not a bug of Java Module. (Editor Bug)
074: * In .diff file could be some whitespaces.
075: * <BR><BR><I>Exception occured:</I><BR>
076: * See .log file for StackTrace
077: *
078: * @author Jan Becicka <Jan.Becicka@sun.com>
079: */
080:
081: public class MethodElem extends org.netbeans.test.java.XRunner {
082:
083: public static void main(java.lang.String[] args) {
084: junit.textui.TestRunner.run(suite());
085: }
086:
087: public MethodElem() {
088: super ("");
089: }
090:
091: public MethodElem(java.lang.String testName) {
092: super (testName);
093: }
094:
095: public static NbTest suite() {
096: return new NbTestSuite(MethodElem.class);
097: }
098:
099: /** "body" of this TestCase
100: * @param o SourceElement - target for generating
101: * @param log log is used for logging StackTraces
102: * @throws Exception
103: * @return true if test passed
104: * false if failed
105: */
106: public boolean go(Object o, java.io.PrintWriter log)
107: throws Exception {
108:
109: // org.openide.src.ClassElement clazz = ((org.openide.src.SourceElement) o).getClasses()[0];
110: boolean passed = true;
111: FileObject fo = (FileObject) o;
112: JavaSource js = JavaSource.forFileObject(fo);
113:
114: Common.addMethod(js, "method1", Common.PARS1, "void", EnumSet
115: .of(Modifier.PUBLIC, Modifier.STATIC));
116: Common.addMethod(js, "method1", Common.PARS2, "int", EnumSet
117: .of(Modifier.PRIVATE, Modifier.SYNCHRONIZED));
118: Common.addMethod(js, "method1", Common.PARS3, "float", EnumSet
119: .of(Modifier.PRIVATE, Modifier.FINAL));
120: Common.addMethod(js, "method2", Common.PARS1, "double", EnumSet
121: .of(Modifier.PUBLIC, Modifier.STATIC));
122: Common.addMethod(js, "method2", Common.PARS2, "boolean",
123: EnumSet.of(Modifier.PUBLIC, Modifier.STATIC));
124: Common.addMethod(js, "method2", Common.PARS3, "void", EnumSet
125: .of(Modifier.PUBLIC, Modifier.STATIC));
126:
127: return passed;
128: }
129:
130: /**
131: */
132: protected void setUp() {
133: super .setUp();
134: name = "JavaTestSourceMethodElem";
135: packageName = "org.netbeans.test.java.testsources";
136: }
137:
138: }
|