|
What this is
This file is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
* Microsystems, Inc. All Rights Reserved.
*/
/*
* FieldElem.java
*
* Created on June 26, 2000, 9:29 AM
*/
package org.netbeans.test.java.generating.ConstructorElem;
import org.netbeans.test.java.Common;
import org.openide.src.Type;
import java.lang.reflect.Modifier;
import org.netbeans.junit.*;
/** Java Module General API Test: ConstructorElement
*
What it tests:
* Creating and handling with ConstructorElement.
* Test is focused on checking of correctness of generated code.
*
How it works:
* New class is created using DataObject.createFromTemplate() and also some ConstructorElements are created.
* These are customized using setters and then added using ClassElement.addConstructor() into ClassElement.
* These actions cause generating of .java code. This code is compared with supposed one.
*
Output:
* Generated Java code.
*
Possible reasons of failure:
* Constructors are not inserted properly
* If there is some constructors in .diff file.
*
Constructors have/return bad properties
* See .diff file to get which ones
*
Bad indentation
* This is propably not a bug of Java Module. (Editor Bug)
* In .diff file could be some whitespaces.
*
Exception occured:
* See .log file for StackTrace
*
* @author Jan Becicka
*/
public class ConstructorElem extends org.netbeans.test.java.XRunner {
public static void main(java.lang.String[] args) {
junit.textui.TestRunner.run(suite());
}
public ConstructorElem() {
super("");
}
public ConstructorElem(java.lang.String testName) {
super(testName);
}
public static NbTest suite() {
return new NbTestSuite(ConstructorElem.class);
}
/** "body" of this TestCase
* @param o SourceElement - target for generating
* @param log log is used for logging StackTraces
* @throws Exception
* @return true if test passed
* false if failed
*/
public boolean go(Object o, java.io.PrintWriter log) throws Exception {
org.openide.src.ClassElement clazz = ((org.openide.src.SourceElement) o).getClasses()[0];
boolean passed = true;
clazz.removeConstructors(clazz.getConstructors());
clazz.addConstructor(Common.createConstructor(""));
clazz.addConstructor(Common.createConstructor(null,Common.PARS1));
clazz.addConstructor(Common.createConstructor(null,Common.PARS2));
clazz.addConstructor(Common.createConstructor(null,Common.PARS3));
if (clazz.getConstructors().length != 4) {
passed = false;
log("Constructors were not properly added");
}
org.openide.src.ConstructorElement ce=clazz.getConstructor(Common.TPARS2);
if (ce==null) {
passed = false;
log("Constructor not found");
} else {
if (!ce.getName().toString().equals(clazz.getName().toString())){
passed = false;
log("getName failed");
}
if (!(ce.getDeclaringClass().getName().getName().equals(name))){
passed = false;
log("getDeclaringClass failed");
}
if (!Common.arrayEquals(ce.getParameters(),Common.PARS2)){
passed = false;
log("getParameters failed");
}
}
return passed;
}
/**
*/
protected void setUp() {
super.setUp();
name = "JavaTestSourceConstructorElem";
packageName = "org.netbeans.test.java.testsources";
}
}
|