IDEA-70191 (Grails 1.4) User should be ably to run Grails Tests defined via @TestFor as JUnit.

This commit is contained in:
Sergey Evdokimov
2011-05-26 14:32:25 +04:00
parent e77ce93e54
commit 5fea40dba7
4 changed files with 53 additions and 3 deletions
@@ -84,6 +84,13 @@ public class JUnitUtil {
if (AnnotationUtil.isAnnotated(aClass, RUN_WITH, true)) return true;
if (psiMethod.getParameterList().getParametersCount() > 0) return false;
if (psiMethod.hasModifierProperty(PsiModifier.STATIC) && BaseTestRunner.SUITE_METHODNAME.equals(psiMethod.getName())) return false;
for (JUnitRecognizer jUnitRecognizer : JUnitRecognizer.EP_NAME.getExtensions()) {
if (jUnitRecognizer.isTestMethod(psiMethod)) {
return true;
}
}
if (!psiMethod.getName().startsWith("test")) return false;
PsiClass testCaseClass = getTestCaseClassOrNull(location);
return testCaseClass != null && psiMethod.getContainingClass().isInheritor(testCaseClass, true);
@@ -122,6 +129,12 @@ public class JUnitUtil {
if (isTestAnnotated(method)) return true;
}
for (JUnitRecognizer jUnitRecognizer : JUnitRecognizer.EP_NAME.getExtensions()) {
if (jUnitRecognizer.isTestClass(psiClass)) {
return true;
}
}
return false;
}
@@ -0,0 +1,22 @@
package com.intellij.execution;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
/**
* @author Sergey Evdokimov
*/
public abstract class JUnitRecognizer {
public static final ExtensionPointName<JUnitRecognizer> EP_NAME = ExtensionPointName.create("com.intellij.junitRecognizer");
public boolean isTestClass(@NotNull PsiClass aClass) {
return false;
}
public boolean isTestMethod(@NotNull PsiMethod method) {
return false;
}
}
@@ -129,16 +129,18 @@ class TestMethod extends TestObject {
}
final JUnitUtil.TestMethodFilter filter = new JUnitUtil.TestMethodFilter(psiClass);
boolean found = false;
boolean testAnnotated = false;
boolean testAnnotatedOrFromRecognizer = false;
for (final PsiMethod method : psiClass.findMethodsByName(methodName, true)) {
if (filter.value(method)) found = true;
if (JUnitUtil.isTestAnnotated(method)) testAnnotated = true;
if (JUnitUtil.isTestAnnotated(method) || isFromRecognizer(method)) {
testAnnotatedOrFromRecognizer = true;
}
}
if (!found) {
throw new RuntimeConfigurationWarning(ExecutionBundle.message("test.method.doesnt.exist.error.message", methodName));
}
if (!AnnotationUtil.isAnnotated(psiClass, JUnitUtil.RUN_WITH, true) && !testAnnotated) {
if (!AnnotationUtil.isAnnotated(psiClass, JUnitUtil.RUN_WITH, true) && !testAnnotatedOrFromRecognizer) {
try {
final PsiClass testCaseClass = JUnitUtil.getTestCaseClass(configurationModule.getModule());
if (!psiClass.isInheritor(testCaseClass, true)) {
@@ -151,4 +153,14 @@ class TestMethod extends TestObject {
}
}
}
private static boolean isFromRecognizer(PsiMethod method) {
for (JUnitRecognizer jUnitRecognizer : JUnitRecognizer.EP_NAME.getExtensions()) {
if (jUnitRecognizer.isTestMethod(method)) {
return true;
}
}
return false;
}
}
+3
View File
@@ -33,6 +33,9 @@
<extensionPoint name="junitPatcher"
interface="com.intellij.execution.JUnitPatcher"/>
<extensionPoint name="junitRecognizer"
interface="com.intellij.execution.JUnitRecognizer"/>
<extensionPoint name="i18nInspectionTool"
interface="com.intellij.codeInspection.FileCheckingInspection"/>
<extensionPoint name="invalidPropertyKeyInspectionTool"