|
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.InnerInterfaces;
import org.netbeans.test.java.Common;
import org.openide.src.*;
import java.lang.reflect.Modifier;
import org.openide.loaders.*;
import org.netbeans.junit.*;
/** Java Module General API test: InnerInterface
*
What it tests:
* Creating and handling with ClassElement.
* Test is focused on checking of correctness of generated code.
*
How it works
* New class is created using DataObject.createFromTemplate() and also some ClassElements are created.
* These are customized using setters, set to be the Interfaces and filled with fields, methods etc.
* Then these ClassElements are added using ClassElement.addClass() into ClassElement.
* These actions cause generating of .java code. This code is compared with supposed one.
*
Output
* Generated Java code.
*
Possible reasons of failure
* Interfaces are not inserted properly:
* If there are some Interfaces in .diff file.
*
Classes have/return bad properies
* See .diff file to get which ones
*
Bad indentation
* This is probably 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 InnerInterfaces extends org.netbeans.test.java.XRunner {
public static void main(java.lang.String[] args) {
junit.textui.TestRunner.run(suite());
}
public InnerInterfaces() {
super("");
}
public InnerInterfaces(java.lang.String testName) {
super(testName);
}
public static NbTest suite() {
return new NbTestSuite(InnerInterfaces.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.setModifiers(Modifier.STATIC);
clazz.setSuperclass(Identifier.create("Object"));
ClassElement inner = new ClassElement();
inner.setName(Identifier.create("InnerClass"));
inner.setSuperclass(Identifier.create("Object"));
inner.setModifiers(Modifier.STATIC | Modifier.FINAL);
inner.setInterfaces(new Identifier[] {Identifier.create("java.awt.event.MouseListener")});
clazz.addClass(inner);
inner = clazz.getClasses()[0];
inner.addMethod(Common.createMethod("method2", Modifier.PUBLIC , org.openide.src.Type.VOID, Common.PARS3));
org.openide.src.FieldElement fe = Common.createField("field");
fe.setInitValue("0.3");
inner.addField(fe);
return passed;
}
/**
*/
protected void setUp() {
super.setUp();
name = "JavaTestSourceInnerInterfaces";
packageName = "org.netbeans.test.java.testsources";
}
}
|