diff --git a/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java b/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java
index f37c769ff533..0cb668505c00 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/AnonymousToInnerTest.java
@@ -18,11 +18,13 @@ package com.intellij.refactoring;
import com.intellij.JavaTestUtil;
import com.intellij.refactoring.anonymousToInner.AnonymousToInnerHandler;
import com.intellij.testFramework.LightCodeInsightTestCase;
+import com.intellij.testFramework.TestDataPath;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
*/
+@TestDataPath("$CONTENT_ROOT/testData")
public class AnonymousToInnerTest extends LightCodeInsightTestCase {
private static final String TEST_ROOT = "/refactoring/anonymousToInner/";
diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InvertBooleanTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InvertBooleanTest.java
index aa7a5084cfea..82b5a2d40ac3 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/InvertBooleanTest.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/InvertBooleanTest.java
@@ -5,16 +5,13 @@ import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.refactoring.invertBoolean.InvertBooleanProcessor;
+import com.intellij.testFramework.TestDataPath;
/**
* @author ven
*/
+@TestDataPath("$CONTENT_ROOT/testData/refactoring/invertBoolean/")
public class InvertBooleanTest extends LightRefactoringParameterizedTestCase {
- @Override
- public String getRelativeBasePath(){
- return "/refactoring/invertBoolean/";
- }
-
@Override
protected void perform() {
PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
diff --git a/java/java-tests/testSrc/com/intellij/refactoring/LightRefactoringParameterizedTestCase.java b/java/java-tests/testSrc/com/intellij/refactoring/LightRefactoringParameterizedTestCase.java
index e2b8e7b9a07f..b822a6684373 100644
--- a/java/java-tests/testSrc/com/intellij/refactoring/LightRefactoringParameterizedTestCase.java
+++ b/java/java-tests/testSrc/com/intellij/refactoring/LightRefactoringParameterizedTestCase.java
@@ -55,12 +55,12 @@ public abstract class LightRefactoringParameterizedTestCase extends LightRefacto
@Override
public void run() {
try {
- final String filePath = getRelativeBasePath() + getBeforeFile(myFileSuffix);
+ final String filePath = getBeforeFile(myFileSuffix);
configureByFile(filePath);
- final File testDir = new File(filePath).getParentFile();
+ final File testDir = new File(getTestDataPath(), filePath).getParentFile();
final String afterName = getAfterFile(myFileSuffix);
- final boolean conflictShouldBeFound = !new File(getTestDataPath() + "/" + testDir, afterName).exists();
+ final boolean conflictShouldBeFound = !new File(testDir, afterName).exists();
try {
perform();
if (conflictShouldBeFound) {
@@ -71,7 +71,7 @@ public abstract class LightRefactoringParameterizedTestCase extends LightRefacto
if (!conflictShouldBeFound) {
fail("Conflict not expected");
} else {
- final File conflicts = new File(getTestDataPath() + "/" + testDir, FileUtilRt.getNameWithoutExtension(myFileSuffix) + CONFLICTS_SUFFIX);
+ final File conflicts = new File(testDir, FileUtilRt.getNameWithoutExtension(myFileSuffix) + CONFLICTS_SUFFIX);
if (!conflicts.exists()) {
fail("Conflict file " + conflicts.getPath() + " not found");
}
@@ -82,7 +82,7 @@ public abstract class LightRefactoringParameterizedTestCase extends LightRefacto
}
if (!conflictShouldBeFound) {
- checkResultByFile(getRelativeBasePath() + getAfterFile(myFileSuffix));
+ checkResultByFile(getAfterFile(myFileSuffix));
}
}
catch (Throwable e) {
diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixParameterizedTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixParameterizedTestCase.java
index 27727bd10b86..73e94a9669dc 100644
--- a/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixParameterizedTestCase.java
+++ b/java/testFramework/src/com/intellij/codeInsight/daemon/quickFix/LightQuickFixParameterizedTestCase.java
@@ -15,13 +15,13 @@
*/
package com.intellij.codeInsight.daemon.quickFix;
-import com.intellij.testFramework.FileBasedTestCaseHelper;
+import com.intellij.testFramework.FileBasedTestCaseHelperEx;
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(com.intellij.testFramework.Parameterized.class)
-public abstract class LightQuickFixParameterizedTestCase extends LightQuickFixTestCase implements FileBasedTestCaseHelper {
+public abstract class LightQuickFixParameterizedTestCase extends LightQuickFixTestCase implements FileBasedTestCaseHelperEx {
@Override
public String getRelativeBasePath() {
return getBasePath();
diff --git a/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelper.java b/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelper.java
index a7838bde580b..615656901f4a 100644
--- a/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelper.java
+++ b/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelper.java
@@ -19,16 +19,15 @@ import org.jetbrains.annotations.Nullable;
/**
* Should be implemented by a test together with annotation @RunWith(com.intellij.testFramework.Parameterized.class)
- * in order to get test run on all test data files located in {@link FileBasedTestCaseHelper#getRelativeBasePath()}.
- *
+ * in order to get test run on all test data files located in directory. The desired directory could be configured
+ * whether by implementing {@link FileBasedTestCaseHelperEx#getRelativeBasePath()} or by annotating test case
+ * with {@link com.intellij.testFramework.TestDataPath} (annotation would enable additional test assistance support, e.g.
+ * navigation from test data to test class/method as well as starting tests right from test data files).
+ *
* BTW @RunWith works also on abstract super classes.
+ * @see LightPlatformCodeInsightTestCase#params(java.lang.Class>)
*/
public interface FileBasedTestCaseHelper {
- /**
- * @return path related to the test data root according to {@link LightPlatformCodeInsightTestCase#getTestDataPath()}
- */
- String getRelativeBasePath();
-
/**
* @return for 'before' files should return core file name or null otherwise
*/
diff --git a/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelperEx.java b/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelperEx.java
new file mode 100644
index 000000000000..f14df27643f6
--- /dev/null
+++ b/platform/testFramework/src/com/intellij/testFramework/FileBasedTestCaseHelperEx.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.testFramework;
+
+
+public interface FileBasedTestCaseHelperEx extends FileBasedTestCaseHelper {
+ /**
+ * @return path related to the test data root according to {@link LightPlatformCodeInsightTestCase#getTestDataPath()}
+ */
+ String getRelativeBasePath();
+}
diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java
index 89d2bb5190f8..40d5f7e1b81d 100644
--- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java
+++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java
@@ -658,7 +658,7 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
/**
* file parameterized tests support
- * @see FileBasedTestCaseHelper
+ * @see FileBasedTestCaseHelperEx
*/
/**
@@ -667,6 +667,11 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
@Parameterized.Parameter(0)
public String myFileSuffix;
+ /**
+ * path to the root of test data in case of com.intellij.testFramework.FileBasedTestCaseHelperEx
+ * or
+ * path to the directory with current test data in case of @TestDataPath
+ */
@Parameterized.Parameter(1)
public String myTestDataPath;
@@ -681,20 +686,32 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
if (!(testCase instanceof FileBasedTestCaseHelper)) {
fail("Parameterized test should implement FileBasedTestCaseHelper");
}
- final FileBasedTestCaseHelper fileBasedTestCase = (FileBasedTestCaseHelper)testCase;
- final String path = fileBasedTestCase.getRelativeBasePath();
-
- assertNotNull("getBasePath() should not return null!", path);
PathManagerEx.replaceLookupStrategy(klass, LightPlatformCodeInsightTestCase.class, com.intellij.testFramework.Parameterized.class);
+ final FileBasedTestCaseHelper fileBasedTestCase = (FileBasedTestCaseHelper)testCase;
String testDataPath = testCase.getTestDataPath();
- final String testDirPath = testDataPath.replace(File.separatorChar, '/') + path;
- File testDir = new File(testDirPath);
+
+ File testDir = null;
+ if (fileBasedTestCase instanceof FileBasedTestCaseHelperEx) {
+ testDir = new File(testDataPath, ((FileBasedTestCaseHelperEx)fileBasedTestCase).getRelativeBasePath());
+ } else {
+ final TestDataPath annotation = klass.getAnnotation(TestDataPath.class);
+ if (annotation == null) {
+ fail("TestCase should implement com.intellij.testFramework.FileBasedTestCaseHelperEx or be annotated with com.intellij.testFramework.TestDataPath");
+ } else {
+ final String trimmedRoot = StringUtil.trimStart(StringUtil.trimStart(annotation.value(), "$CONTENT_ROOT"), "$PROJECT_ROOT");
+ final String lastPathComponent = new File(testDataPath).getName();
+ final int idx = trimmedRoot.indexOf(lastPathComponent);
+ testDataPath = testDataPath.replace(File.separatorChar, '/') + (idx > 0 ? trimmedRoot.substring(idx + lastPathComponent.length()) : trimmedRoot);
+ testDir = new File(testDataPath);
+ }
+ }
+
final File[] files = testDir.listFiles();
if (files == null) {
- fail("Test files not found in " + testDirPath);
+ fail("Test files not found in " + testDir.getPath());
}
final List