1 package com
.intellij
.refactoring
;
3 import com
.intellij
.JavaTestUtil
;
4 import com
.intellij
.codeInsight
.TargetElementUtilBase
;
5 import com
.intellij
.idea
.Bombed
;
6 import com
.intellij
.openapi
.roots
.ProjectRootManager
;
7 import com
.intellij
.openapi
.vfs
.VirtualFile
;
8 import com
.intellij
.psi
.PsiClass
;
9 import com
.intellij
.psi
.PsiElement
;
10 import com
.intellij
.psi
.search
.GlobalSearchScope
;
11 import com
.intellij
.refactoring
.safeDelete
.SafeDeleteHandler
;
12 import com
.intellij
.testFramework
.IdeaTestUtil
;
13 import org
.jetbrains
.annotations
.NonNls
;
16 import java
.util
.Calendar
;
18 public class SafeDeleteTest
extends MultiFileTestCase
{
19 private VirtualFile myRootBefore
;
22 protected String
getTestDataPath() {
23 return JavaTestUtil
.getJavaTestDataPath();
26 protected boolean clearModelBeforeConfiguring() {
30 public void testImplicitCtrCall() throws Exception
{
35 catch (BaseRefactoringProcessor
.ConflictsInTestsException e
) {
36 String message
= e
.getMessage();
37 assertTrue(message
, message
.startsWith("constructor <b><code>Super.Super()</code></b> has 1 usage that is not safe to delete"));
40 public void testImplicitCtrCall2() throws Exception
{
45 catch (BaseRefactoringProcessor
.ConflictsInTestsException e
) {
46 String message
= e
.getMessage();
47 assertTrue(message
, message
.startsWith("constructor <b><code>Super.Super()</code></b> has 1 usage that is not safe to delete"));
51 public void testMultipleInterfacesImplementation() throws Exception
{
56 @Bombed(day
= 3, month
= Calendar
.FEBRUARY
, description
= "should not delete method implementing IBar interface")
57 public void testMultipleInterfacesImplementationThroughCommonInterface() throws Exception
{
62 public void testExtendsList() throws Exception
{
67 public void testEnumConstructorParameter() throws Exception
{
72 public void testRemoveOverridersInspiteOfUnsafeUsages() throws Exception
{
75 BaseRefactoringProcessor
.ConflictsInTestsException
.setTestIgnore(true);
79 BaseRefactoringProcessor
.ConflictsInTestsException
.setTestIgnore(false);
83 private void doTest(@NonNls final String qClassName
) throws Exception
{
84 doTest(new PerformAction() {
85 public void performAction(VirtualFile rootDir
, VirtualFile rootAfter
) throws Exception
{
86 SafeDeleteTest
.this.performAction(qClassName
);
87 IdeaTestUtil
.assertDirectoriesEqual(rootAfter
, myRootBefore
, IdeaTestUtil
.CVS_FILE_FILTER
);
92 private void performAction(String qClassName
) throws Exception
{
93 PsiClass aClass
= myJavaFacade
.findClass(qClassName
, GlobalSearchScope
.allScope(getProject()));
94 assertNotNull("Class " + qClassName
+ " not found", aClass
);
96 String root
= ProjectRootManager
.getInstance(getProject()).getContentRoots()[0].getPath();
97 myRootBefore
= configureByFiles(new File(root
), aClass
.getContainingFile().getVirtualFile());
98 final PsiElement psiElement
= TargetElementUtilBase
99 .findTargetElement(myEditor
, TargetElementUtilBase
.ELEMENT_NAME_ACCEPTED
| TargetElementUtilBase
.REFERENCED_ELEMENT_ACCEPTED
);
101 SafeDeleteHandler
.invoke(getProject(), new PsiElement
[]{psiElement
}, false);
104 protected String
getTestRoot() {
105 return "/refactoring/safeDelete/";