alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

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.integrity.GetDeclaringClass;

import org.netbeans.test.java.Common;
import org.openide.src.*;
import java.lang.reflect.Modifier;
import org.netbeans.junit.*;
import org.openide.cookies.SaveCookie;
import org.openide.filesystems.FileUtil;

/** Java Module Integrity API Test: GetDeclaringClass
 * 

What it tests:
* getCeclaringClass should return declaring class of Element. * This test checks, if declaring class is always returned correctly. * Especially in cases, when Elements are moved from one class to another one, or if they are removed from class. *

How it works:
* There is manipulated with Elements and after doing that is allways logged, what getDeclaringClass()'s returns. *

Output:
* Log file produced by getDeclaringClass()) *

Possible reasons of failure:
*

getDeclaringClass has returned bad class
* See .diff file which one. *

Exception occured:
* See .out or .diff file for StackTrace * * * @author Jan Becicka */ public class GetDeclaringClass extends org.netbeans.test.java.LogTestCase { String name = "GetDeclaringClassTestTarget"; String packageName = "org.netbeans.test.java.testsources"; public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } public GetDeclaringClass() { super(""); } public GetDeclaringClass(java.lang.String testName) { super(testName); } public static NbTest suite() { return new NbTestSuite(GetDeclaringClass.class); } public void testRun() { try { _testIt(); } catch (Exception e) { assertTrue(e.toString(), false); } } public void _testIt() throws Exception { org.openide.src.ClassElement clazz=null; boolean passed = true; try { clazz = Common.createClass(FileUtil.toFileObject(classPathWorkDir), packageName,name); } catch (Exception e) { e.printStackTrace(log); assertTrue(e.toString(), false); } ClassElement sourceClazz = ClassElement.forName("org.netbeans.test.java.testsources.GetDeclaringClassTest", FileUtil.toFileObject(classPathWorkDir)); clazz.removeConstructors(clazz.getConstructors()); clazz.addClass(sourceClazz.getClasses()[0]); ref(clazz.getClasses()[0].getDeclaringClass().getName().getFullName()); clazz.addConstructor(sourceClazz.getConstructors()[0]); ref(clazz.getConstructors()[0].getDeclaringClass().getName().getFullName()); clazz.addField(sourceClazz.getFields()[0]); ref(clazz.getFields()[0].getDeclaringClass().getName().getFullName()); clazz.addInitializer(sourceClazz.getInitializers()[0]); ref(clazz.getInitializers()[0].getDeclaringClass().getName().getFullName()); clazz.addMethod(sourceClazz.getMethods()[0]); ref(clazz.getMethods()[0].getDeclaringClass().getName().getFullName()); MethodElement me = clazz.getMethods()[0]; FieldElement fe = clazz.getFields()[0]; InitializerElement ie = clazz.getInitializers()[0]; ConstructorElement coe = clazz.getConstructors()[0]; ClassElement ce = clazz.getClasses()[0]; clazz.removeClass(ce); ref(ce.getDeclaringClass().getName().getFullName()); clazz.removeConstructor(coe); ref(coe.getDeclaringClass().getName().getFullName()); clazz.removeInitializer(ie); ref(ie.getDeclaringClass().getName().getFullName()); clazz.removeMethod(me); ref(me.getDeclaringClass().getName().getFullName()); clazz.removeField(fe); ref(me.getDeclaringClass().getName().getFullName()); org.netbeans.modules.java.JavaDataObject DO = (org.netbeans.modules.java.JavaDataObject) clazz.getSource().getCookie(org.netbeans.modules.java.JavaDataObject.class); ((SaveCookie) DO.getCookie(SaveCookie.class)).save(); DO.delete(); } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.