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-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.jmi.javamodel.codegen;

import java.io.IOException;
import java.lang.reflect.Modifier;
import java.util.Collections;
import org.netbeans.jmi.javamodel.*;
import org.netbeans.junit.*;
import org.openide.filesystems.FileStateInvalidException;

/**
 *
 * @author  Pavel Flaska
 */
public class SuperClassTest extends NbTestCase {
    
    JavaClass clazz;
    String cbn;
    JavaModelPackage pkg;
    
    /** Creates a new instance of SuperClassTest */
    public SuperClassTest() {
        super("SuperClassTest");
    }
    
    protected void setUp() {
        clazz = Utility.findClass("org.netbeans.test.codegen.SuperClassTest");
        pkg = (JavaModelPackage) clazz.refImmediatePackage();
    }
    
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite(SuperClassTest.class);
        return suite;
    }

    public void testAddClass() throws IOException, FileStateInvalidException {
        boolean fail = true;
        Utility.beginTrans(true);
        try {
            MultipartId multi = pkg.getMultipartId().createMultipartId("SecondInnerClass", null, null);
            JavaClass innerClass = pkg.getJavaClass().createJavaClass(
                "ThirdInnerClass",     // name
                null,                  // annnotations
                Modifier.STATIC,       // modifiers
                null,                  // javadoc
                null,                  // javaDoc text
                Collections.EMPTY_LIST, // empty features
                multi,                 // superclass
                null,                  // interfaces
                null
                );
            clazz.getContents().add(innerClass);
            fail = false;
        } finally {
            Utility.endTrans(fail);
        }
        assertFile("File is not correctly generated.",
            Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"),
            getGoldenFile("testAddClass_SuperClassTest.pass"),
            getWorkDir()
        );
    }

    public void testChange() throws IOException, FileStateInvalidException {
        boolean fail = true;
        Utility.beginTrans(true);
        try {
            JavaClass inner = (JavaClass) clazz.getContents().get(2);
            MultipartId id = pkg.getMultipartId().createMultipartId("SuperClassTest", null, null);
            inner.setSuperClass((JavaClass) clazz.getContents().get(1));
            inner.setSuperClassName(id);
            fail = false;
        } finally {
            Utility.endTrans(fail);
        }
        assertFile("File is not correctly generated.",
            Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"),
            getGoldenFile("testChange_SuperClassTest.pass"),
            getWorkDir()
        );
    }

    public void testAddSuper() throws FileStateInvalidException, IOException {
        boolean fail = true;
        Utility.beginTrans(true);
        try {
            JavaClass inner = (JavaClass) clazz.getContents().get(1);
            MultipartId id = pkg.getMultipartId().createMultipartId("NoExt", null, null);
            inner.setSuperClassName(id);
            inner.setSuperClass(clazz);
            fail = false;
        } finally {
            Utility.endTrans(fail);
        }
        assertFile("File is not correctly generated.",
            Utility.getFile(getDataDir(), "org/netbeans/test/codegen/SuperClassTest.java"),
            getGoldenFile("testAddSuper_SuperClassTest.pass"),
            getWorkDir()
        );
    }
        
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    }
    
}
... 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.