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.
 */

/*
 * ForName.java
 *
 * Created on September 19, 2000, 1:39 PM
 */

package org.netbeans.test.java.integrity.GetClass;

import org.openide.filesystems.FileUtil;
import org.openide.src.ClassElement;
import org.openide.src.Identifier;


/** Java Module Integrity API Test: GetClass
 * 

What it tests:
* Capability of module to find class (inner or outer) in .java file. *

What has to be set:
* testbase/testfs has to be mounted. *

How it works:
* Test tries to find known classes using ClassElement.getClass() and SourceElement.getClass(); *

Output:
* Places, where were known classes found. This is compared with golden file. *

Possible reasons of failure:
*

Some classes were not found
* See .diff file which ones. *

Exception occured:
* See .out or .diff file for StackTrace * * @author Jan Becicka * @version */ public class GetClass extends org.netbeans.test.java.LogTestCase { public void testRun() { try { _testIt(); } catch (Exception e) { assertTrue(e.toString(), false); } } public GetClass(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(GetClass.class); } public void _testIt() throws Exception { ClassElement ce = ClassElement.forName("org.netbeans.test.java.testsources.GetClassTest", FileUtil.toFileObject(classPathWorkDir)); org.openide.src.SourceElement se = ce.getSource(); ClassElement ce1, ce2; //SN ce1 = se.getClass(Identifier.create("GetClassTest")); ce2 = ce1.getClass(Identifier.create("InnerClass2")); if (ce1==null){ ref("null: GetClassTest not found!"); } else { ref(ce1.getName().getFullName()); } if (ce2==null){ ref("null: NewClass2 not found!"); } else { ref(ce2.getName().getFullName()); } //FQN ce1 = se.getClass(Identifier.create("org.netbeans.test.java.testsources.NewClass3","NewClass3")); ce2 = ce1.getClass(Identifier.create("org.netbeans.test.java.testsources.NewClass3.InnerClass1","InnerClass1")); if (ce1 == null){ ref("null: GetClassTest not found!"); } else { ref(ce1.getName().getFullName()); } if (ce2==null){ ref("null: NewClass3 not found!"); } else { ref(ce2.getName().getFullName()); } //FQN is bad! => should return null ce1 = se.getClass(Identifier.create("org.netbeans.test.java.testsources.GetClssTest","GetClassTest")); ce2 = ce.getClass(Identifier.create("org.netbeans.test.java.testsources.GetClssTest.InnerClass1","InnerClass1")); if (ce1 == null){ ref("null - OK"); } else { ref("Not null! but should be null!"); } if (ce2==null){ ref("null - OK"); } else { ref("Not null! but should be null!"); } } }
... 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.