Ben Gruver | 07e6ade | 2015-03-28 12:50:36 -0700 | [diff] [blame] | 1 | package org.jf.smalidea; |
| 2 | |
| 3 | import com.intellij.openapi.roots.JavaProjectRootsUtil; |
| 4 | import com.intellij.openapi.vfs.VirtualFile; |
| 5 | import com.intellij.psi.PsiClass; |
Ben Gruver | 07e6ade | 2015-03-28 12:50:36 -0700 | [diff] [blame] | 6 | import com.intellij.psi.search.GlobalSearchScope; |
| 7 | import com.intellij.refactoring.MultiFileTestCase; |
| 8 | import com.intellij.refactoring.PackageWrapper; |
| 9 | import com.intellij.refactoring.move.moveClassesOrPackages.AutocreatingSingleSourceRootMoveDestination; |
| 10 | import com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesProcessor; |
Ben Gruver | 07e6ade | 2015-03-28 12:50:36 -0700 | [diff] [blame] | 11 | import org.jetbrains.annotations.NotNull; |
| 12 | |
| 13 | import java.util.List; |
| 14 | |
| 15 | public class ClassMoveTest extends MultiFileTestCase { |
| 16 | @Override |
| 17 | protected String getTestDataPath() { |
| 18 | return "testData"; |
| 19 | } |
| 20 | |
| 21 | @NotNull |
| 22 | @Override |
| 23 | protected String getTestRoot() { |
| 24 | return "/classMove/"; |
| 25 | } |
| 26 | |
| 27 | public void testBasicFromNoPackage() { |
| 28 | doTest("blah", "my"); |
| 29 | } |
| 30 | |
| 31 | public void testBasicToNoPackage() { |
| 32 | doTest("my.blah", ""); |
| 33 | } |
| 34 | |
| 35 | private void doTest(@NotNull final String oldQualifiedName, @NotNull final String newPackage) { |
| 36 | doTest(new PerformAction() { |
| 37 | @Override |
| 38 | public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception { |
| 39 | doMove(oldQualifiedName, newPackage); |
| 40 | } |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | private void doMove(String oldQualifiedName, final String newPackage) throws Exception { |
| 45 | final PsiClass testClass = myJavaFacade.findClass(oldQualifiedName, GlobalSearchScope.allScope(getProject())); |
| 46 | |
Ben Gruver | 07e6ade | 2015-03-28 12:50:36 -0700 | [diff] [blame] | 47 | final List<VirtualFile> contentSourceRoots = |
| 48 | JavaProjectRootsUtil.getSuitableDestinationSourceRoots(getProject()); |
| 49 | |
| 50 | new MoveClassesOrPackagesProcessor(getProject(), new PsiClass[] {testClass}, |
| 51 | new AutocreatingSingleSourceRootMoveDestination(new PackageWrapper(getPsiManager(), newPackage), |
| 52 | contentSourceRoots.get(0)), false, false, null).run(); |
Ben Gruver | 07e6ade | 2015-03-28 12:50:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } |