test data
[fedora-idea.git] / java / java-tests / testSrc / com / intellij / refactoring / SafeDeleteTest.java
blob45f0bbf0a68362fb1034f289c6690b7925a0ad16
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;
15 import java.io.File;
16 import java.util.Calendar;
18 public class SafeDeleteTest extends MultiFileTestCase {
19 private VirtualFile myRootBefore;
21 @Override
22 protected String getTestDataPath() {
23 return JavaTestUtil.getJavaTestDataPath();
26 protected boolean clearModelBeforeConfiguring() {
27 return true;
30 public void testImplicitCtrCall() throws Exception {
31 try {
32 doTest("Super");
33 fail();
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 {
41 try {
42 doTest("Super");
43 fail();
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 {
52 myDoCompare = false;
53 doTest("IFoo");
56 @Bombed(day = 3, month = Calendar.FEBRUARY, description = "should not delete method implementing IBar interface")
57 public void testMultipleInterfacesImplementationThroughCommonInterface() throws Exception {
58 myDoCompare = false;
59 doTest("IFoo");
62 public void testExtendsList() throws Exception {
63 myDoCompare = false;
64 doTest("B");
67 public void testEnumConstructorParameter() throws Exception {
68 myDoCompare = false;
69 doTest("UserFlags");
72 public void testRemoveOverridersInspiteOfUnsafeUsages() throws Exception {
73 myDoCompare = false;
74 try {
75 BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(true);
76 doTest("A");
78 finally {
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);
89 });
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/";