KickJava   Java API By Example, From Geeks To Geeks.

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


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.SuperClassInterfaces;
27
28 import com.sun.source.tree.ClassTree;
29 import com.sun.source.tree.Tree;
30 import org.netbeans.test.java.Common;
31 import java.lang.reflect.Modifier JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collections JavaDoc;
34 import java.util.List JavaDoc;
35 import org.netbeans.api.java.source.CancellableTask;
36 import org.netbeans.api.java.source.JavaSource;
37 import org.netbeans.api.java.source.JavaSource.Phase;
38 import org.netbeans.api.java.source.WorkingCopy;
39 import org.openide.loaders.*;
40 import org.netbeans.junit.*;
41 import org.openide.filesystems.FileObject;
42
43 /** <B>Java Module General API test: InnerInterface</B>
44  * <BR><BR><I>What it tests:</I><BR>
45  * Creating and handling with ClassElement.
46  * Test is focused on checking of correctness of generated code.
47  * <BR><BR><I>How it works</I><BR>
48  * New class is created using DataObject.createFromTemplate() and also some ClassElements are created.
49  * These are customized using setters, set to be the Interfaces and filled with fields, methods etc.
50  * Then these ClassElements are added using ClassElement.addClass() into ClassElement.
51  * These actions cause generating of .java code. This code is compared with supposed one.
52  * <BR><BR><I>Output</I><BR>
53  * Generated Java code.
54  * <BR><BR><I>Possible reasons of failure</I><BR>
55  * <U>Interfaces are not inserted properly:</U><BR>
56  * If there are some Interfaces in .diff file.
57  * <BR><BR><U>Classes have/return bad properies</U><BR>
58  * See .diff file to get which ones
59  * <BR><BR><U>Bad indentation</U><BR>
60  * This is probably not a bug of Java Module. (->Editor Bug)
61  * In .diff file could be some whitespaces.
62  * <BR><BR><U>Exception occured</U><BR><BR>
63  * See .log file for StackTrace
64  *
65  * @author Jan Becicka <Jan.Becicka@sun.com>
66  */

67
68
69 public class SuperClassInterfaces extends org.netbeans.test.java.XRunner {
70     
71     public static void main(java.lang.String JavaDoc[] args) {
72         junit.textui.TestRunner.run(suite());
73     }
74     
75     public SuperClassInterfaces() {
76         super("");
77     }
78     
79     public SuperClassInterfaces(java.lang.String JavaDoc testName) {
80         super(testName);
81     }
82     
83     public static NbTest suite() {
84         return new NbTestSuite(SuperClassInterfaces.class);
85     }
86     
87     /** "body" of this TestCase
88      * @param o SourceElement - target for generating
89      * @param log log is used for logging StackTraces
90      * @throws Exception
91      * @return true if test passed
92      * false if failed
93      */

94     
95     public boolean go(Object JavaDoc o, java.io.PrintWriter JavaDoc log) throws Exception JavaDoc {
96         
97         FileObject fo = (FileObject) o;
98         JavaSource js = JavaSource.forFileObject(fo);
99         List JavaDoc<String JavaDoc> list = new ArrayList JavaDoc<String JavaDoc>();
100         list.add("java.util.List");
101         list.add("java.io.Closeable");
102         Common.addExtendImplementClause(js, "java.io.File", list);
103         return true;
104     }
105    
106     /**
107      */

108     protected void setUp() {
109         super.setUp();
110         name = "JavaTestSourceInnerInterfaces";
111         packageName = "org.netbeans.test.java.testsources";
112     }
113     
114 }
115
Popular Tags