|
What this is
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.moveclass; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.util.*; import junit.textui.TestRunner; import org.netbeans.modules.refactoring.api.MoveClassRefactoring; import org.netbeans.modules.refactoring.api.RefactoringSupport; import org.netbeans.jmi.javamodel.*; 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.FileObject; import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.Repository; import org.openide.filesystems.URLMapper; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; /** * @author Daniel Prusa */ public class MoveClassTest extends NbTestCase { private static String[] resultFiles = { "abc/test_folder/BaseClass", "abc/test_folder/ClassOne", "abc/test_folder/ExtendedMoveMe", "abc/AClass", "abc/BClass", "abc/CClass", "abc/MainClass", "folder/sub_folder/sub_folder/MoveMe" }; private String JAVA_EXT = "java"; private String PASS_EXT = "pass"; private String PATH_PREFIX = "org/netbeans/test/moveclass/"; /** Need to be defined because of JUnit */ public MoveClassTest(String name) { super(name); } public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); suite.addTest(new MoveClassTest("testMoveClass")); return suite; } FileObject targetFolder; Resource resource; protected void setUp() throws MalformedURLException, FileStateInvalidException { JavaClass jc = Utility.findClass("org.netbeans.test.moveclass.abc.test_folder.MoveMe"); resource = (Resource) jc.refImmediateComposite(); targetFolder = URLMapper.findFileObject(Utility.getFile(getDataDir(),"org/netbeans/test/moveclass/folder/sub_folder/sub_folder").toURL()); } public void testMoveClass() { RefactoringSupport support = RefactoringSupport.getDefault(); Collection list = new ArrayList(1); list.add(resource); MoveClassRefactoring refactoring = new MoveClassRefactoring(list); refactoring.preCheck(); refactoring.setParameters(targetFolder); Collection result = new ArrayList(); refactoring.prepare(result); assertNull(support.doRefactoring(result, "move class", null)); JavaMetamodel.getUndoManager().saveAll(); try { for (int x = 0; x < resultFiles.length; x++) { String fileName = PATH_PREFIX + resultFiles[x] + '.' + JAVA_EXT; int index = resultFiles[x].lastIndexOf('/') + 1; String passName = resultFiles[x].substring(index) + '.' + PASS_EXT; assertFile(Utility.getFile(getDataDir(), fileName), getGoldenFile(passName), getWorkDir()); } } catch (FileStateInvalidException e) { fail(e.getMessage()); } catch (IOException e) { fail(e.getMessage()); } } /** * @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 |
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.