Files
openide/java/java-tests/testSrc/com/intellij/refactoring/FindMethodDuplicatesBaseTest.java
2011-02-17 14:00:16 +03:00

51 lines
1.6 KiB
Java

/*
* User: anna
* Date: 22-Jul-2008
*/
package com.intellij.refactoring;
import com.intellij.JavaTestUtil;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.refactoring.util.duplicates.MethodDuplicatesHandler;
import com.intellij.testFramework.LightCodeInsightTestCase;
public abstract class FindMethodDuplicatesBaseTest extends LightCodeInsightTestCase {
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
protected void doTest() throws Exception {
doTest(true);
}
protected void doTest(final boolean shouldSucceed) throws Exception {
final String filePath = getTestFilePath();
configureByFile(filePath);
final PsiElement targetElement = TargetElementUtilBase.findTargetElement(getEditor(), TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
final PsiMethod psiMethod = (PsiMethod)targetElement;
try {
MethodDuplicatesHandler.invokeOnScope(getProject(), psiMethod, new AnalysisScope(getFile()));
}
catch (RuntimeException e) {
if (shouldSucceed) {
fail("duplicates were not found");
}
return;
}
if (shouldSucceed) {
checkResultByFile(filePath + ".after");
} else {
fail("duplicates found");
}
}
protected abstract String getTestFilePath();
}