KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > java > integrity > GetDeclaringClass


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.integrity.GetDeclaringClass;
27
28 import org.netbeans.test.java.Common;
29 //import org.openide.src.*;
30
import java.lang.reflect.Modifier JavaDoc;
31 import org.netbeans.junit.*;
32 import org.openide.cookies.SaveCookie;
33 import org.openide.filesystems.FileUtil;
34
35 /** <B>Java Module Integrity API Test: GetDeclaringClass</B>
36  * <BR><BR><I>What it tests:</I><BR>
37  * getCeclaringClass should return declaring class of Element.
38  * This test checks, if declaring class is always returned correctly.
39  * Especially in cases, when Elements are moved from one class to another one, or if they are removed from class.
40  * <BR><BR><I>How it works:</I><BR>
41  * There is manipulated with Elements and after doing that is allways logged, what getDeclaringClass()'s returns.
42  * <BR><BR><I>Output:</I><BR>
43  * Log file produced by getDeclaringClass())
44  * <BR><BR><I>Possible reasons of failure:</I><BR>
45  * <BR><BR><U>getDeclaringClass has returned bad class</U><BR>
46  * See .diff file which one.
47  * <BR><BR><U>Exception occured:</U><BR>
48  * See .out or .diff file for StackTrace
49  *
50  *
51  * @author Jan Becicka <Jan.Becicka@sun.com>
52  */

53
54
55 public class GetDeclaringClass extends org.netbeans.test.java.LogTestCase {
56     
57     String JavaDoc name = "GetDeclaringClassTestTarget";
58     String JavaDoc packageName = "org.netbeans.test.java.testsources";
59     
60     public static void main(java.lang.String JavaDoc[] args) {
61         junit.textui.TestRunner.run(suite());
62     }
63     
64     public GetDeclaringClass() {
65         super("");
66     }
67     
68     public GetDeclaringClass(java.lang.String JavaDoc testName) {
69         super(testName);
70     }
71     
72     public static NbTest suite() {
73         return new NbTestSuite(GetDeclaringClass.class);
74     }
75     
76     public void testRun() {
77         try {
78             _testIt();
79         } catch (Exception JavaDoc e) {
80             assertTrue(e.toString(), false);
81         }
82     }
83     
84     
85     public void _testIt() throws Exception JavaDoc {
86         
87 // org.openide.src.ClassElement clazz=null;
88
// boolean passed = true;
89
// try {
90
// clazz = Common.createClass(FileUtil.toFileObject(classPathWorkDir), packageName,name);
91
// } catch (Exception e) {
92
// e.printStackTrace(log);
93
// assertTrue(e.toString(), false);
94
// }
95
//
96
// ClassElement sourceClazz = ClassElement.forName("org.netbeans.test.java.testsources.GetDeclaringClassTest", FileUtil.toFileObject(classPathWorkDir));
97
// clazz.removeConstructors(clazz.getConstructors());
98
//
99
// clazz.addClass(sourceClazz.getClasses()[0]);
100
// ref(clazz.getClasses()[0].getDeclaringClass().getName().getFullName());
101
//
102
// clazz.addConstructor(sourceClazz.getConstructors()[0]);
103
// ref(clazz.getConstructors()[0].getDeclaringClass().getName().getFullName());
104
//
105
// clazz.addField(sourceClazz.getFields()[0]);
106
// ref(clazz.getFields()[0].getDeclaringClass().getName().getFullName());
107
//
108
// clazz.addInitializer(sourceClazz.getInitializers()[0]);
109
// ref(clazz.getInitializers()[0].getDeclaringClass().getName().getFullName());
110
//
111
// clazz.addMethod(sourceClazz.getMethods()[0]);
112
// ref(clazz.getMethods()[0].getDeclaringClass().getName().getFullName());
113
//
114
// MethodElement me = clazz.getMethods()[0];
115
// FieldElement fe = clazz.getFields()[0];
116
// InitializerElement ie = clazz.getInitializers()[0];
117
// ConstructorElement coe = clazz.getConstructors()[0];
118
// ClassElement ce = clazz.getClasses()[0];
119
//
120
// clazz.removeClass(ce);
121
// ref(ce.getDeclaringClass().getName().getFullName());
122
//
123
// clazz.removeConstructor(coe);
124
// ref(coe.getDeclaringClass().getName().getFullName());
125
//
126
// clazz.removeInitializer(ie);
127
// ref(ie.getDeclaringClass().getName().getFullName());
128
//
129
// clazz.removeMethod(me);
130
// ref(me.getDeclaringClass().getName().getFullName());
131
//
132
// clazz.removeField(fe);
133
// ref(me.getDeclaringClass().getName().getFullName());
134
//
135
// org.netbeans.modules.java.JavaDataObject DO = (org.netbeans.modules.java.JavaDataObject) clazz.getSource().getCookie(org.netbeans.modules.java.JavaDataObject.class);
136
// ((SaveCookie) DO.getCookie(SaveCookie.class)).save();
137
// DO.delete();
138

139     }
140 }
141
Popular Tags