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.test.refactoring.rename;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import junit.textui.TestRunner;
import org.netbeans.modules.refactoring.api.RefactoringSupport;
import org.netbeans.modules.refactoring.api.RenameRefactoring;
import org.netbeans.jmi.javamodel.JavaClass;
import org.netbeans.jmi.javamodel.JavaModelPackage;
import org.netbeans.jmi.javamodel.JavaPackage;
import org.netbeans.junit.NbTestCase;
import org.netbeans.junit.NbTestSuite;
import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
import org.netbeans.test.refactoring.Utility;
import org.openide.filesystems.FileStateInvalidException;


/**
 * @author  Jan Becicka
 */
public class RenamePackageTest extends NbTestCase {
    
    /** Need to be defined because of JUnit */
    public RenamePackageTest(String name) {
        super(name);
    }
    
    public static NbTestSuite suite() {
        NbTestSuite suite = new NbTestSuite();
        suite.addTest(new RenamePackageTest("testRename"));
        suite.addTest(new RenamePackageTest("testCheckTestClass"));
        suite.addTest(new RenamePackageTest("testCheckTestException"));
        suite.addTest(new RenamePackageTest("testCheckTestInterface"));
        suite.addTest(new RenamePackageTest("testCheckTestPackages"));

        JavaClass jc = Utility.findClass("org.netbeans.test.rename.testpackage.TestClass");
        
        pckg = ((JavaModelPackage) jc.refOutermostPackage()).getJavaPackage().resolvePackage("org.netbeans.test.rename.testpackage");

        return suite;
    }
    
    private static JavaPackage pckg;

    private static final String newName = "test2";
    
    public void testRename() {
        
        RefactoringSupport support = RefactoringSupport.getDefault();
        RenameRefactoring refactoring = new RenameRefactoring(pckg);
        refactoring.setParameters(newName);
        Collection result = new ArrayList();
        refactoring.prepare(result);
        assertNull(support.doRefactoring(result, "rename package", null));
        JavaMetamodel.getUndoManager().saveAll();
    }
    
    public void testCheckTestClass() throws IOException {
        assertFile("TestClass.java is not correct", Utility.getFile(getDataDir(), "org/netbeans/test/rename/test2/TestClass.java"), getGoldenFile(), getWorkDir()) ; 
    }
    
    public void testCheckTestException() throws IOException {
        assertFile("TestException.java is not correct", Utility.getFile(getDataDir(), "org/netbeans/test/rename/test2/TestException.java"), getGoldenFile(), getWorkDir()) ; 
    }

    public void testCheckTestInterface() throws IOException {
        assertFile("TestInterface.java is not correct", Utility.getFile(getDataDir(), "org/netbeans/test/rename/test2/TestInterface.java"), getGoldenFile(), getWorkDir()) ; 
    }
    
    public void testCheckTestPackages() throws IOException {
        assertFile("TestPackages.java is not correct", Utility.getFile(getDataDir(), "org/netbeans/test/rename/test2/TestPackages.java"), getGoldenFile(), getWorkDir()) ; 
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        TestRunner.run(suite());
    }
}
... 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.