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.Identity;

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


/** Java Module Integrity API Test: Identity
 * 

What it tests:
* ClassElement.forName() should return the same class, no matter how many times you call it, * even if System.gc() is called between two calls of ClassElement.forName. *

How it works:
* This test is only simple loop, which body has ClassElement.forName() and System.gc() calls. * Result from ClassElement.forName() is logged and then compared with golden file. *

Output:
* Log file produced by ClassElelemnt.forName() *

Possible reasons of failure:
*

Some call of forName returns bad class (or null)
* See .diff file which one. *

Exception occured:
* See .out or .diff file for StackTrace * * @author Jan Becicka * @version */ public class Identity extends org.netbeans.test.java.LogTestCase { public void testRun() { try { _testIt(); } catch (Exception e) { assertTrue(e.toString(), false); } } public Identity(java.lang.String testName) { super(testName); } public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(Identity.class); } static int LOOPCOUNT = 10; public void _testIt() throws Exception { FileObject artefact=FileUtil.toFileObject(classPathWorkDir); ClassElement ce = ClassElement.forName("org.netbeans.test.java.testsources.TopLevelClass$InnerClass", artefact); for (int i=0;i < LOOPCOUNT;i++){ if (ce==ClassElement.forName("org.netbeans.test.java.testsources.TopLevelClass$InnerClass", artefact)){ ref("forName returned right reference"); } else { ref("forName returned wrong reference!"); } System.gc(); Thread.currentThread().sleep(i*500); } } }
... 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.