From 32c1b27f853230c9dfa7ba78d79444660e78937d Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 14 Sep 2012 12:35:33 +0400 Subject: [PATCH] NCDF fix for broken installation: if junit was removed from lib folder --- .../src/com/intellij/execution/junit/JUnitUtil.java | 7 ++++--- .../intellij/execution/junit/JUnit4Framework.java | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java index 493f01137da4..495068807e25 100644 --- a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java +++ b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java @@ -42,11 +42,12 @@ public class JUnitUtil { @NonNls public static final String TESTCASE_CLASS = "junit.framework.TestCase"; @NonNls private static final String TEST_INTERFACE = "junit.framework.Test"; @NonNls private static final String TESTSUITE_CLASS = "junit.framework.TestSuite"; - @NonNls private static final String TEST_ANNOTATION = "org.junit.Test"; + @NonNls public static final String TEST_ANNOTATION = "org.junit.Test"; + @NonNls public static final String IGNORE_ANNOTATION = "org.junit.Ignore"; @NonNls public static final String RUN_WITH = "org.junit.runner.RunWith"; @NonNls public static final String SUITE_METHOD_NAME = "suite"; - private static final String BEFORE_ANNOTATION_NAME = "org.junit.Before"; - private static final String AFTER_ANNOTATION_NAME = "org.junit.After"; + public static final String BEFORE_ANNOTATION_NAME = "org.junit.Before"; + public static final String AFTER_ANNOTATION_NAME = "org.junit.After"; private static final String PARAMETRIZED_PARAMETERS_ANNOTATION_NAME = "org.junit.runners.Parameterized.Parameters"; private static final String AFTER_CLASS_ANNOTATION_NAME = "org.junit.AfterClass"; private static final String BEFORE_CLASS_ANNOTATION_NAME = "org.junit.BeforeClass"; diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java b/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java index 066a651fbbbf..3f724c4df2de 100644 --- a/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java +++ b/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java @@ -48,7 +48,7 @@ public class JUnit4Framework extends JavaTestFramework { } protected String getMarkerClassFQName() { - return "org.junit.Test"; + return JUnitUtil.TEST_ANNOTATION; } @NotNull @@ -70,7 +70,7 @@ public class JUnit4Framework extends JavaTestFramework { @Override protected PsiMethod findSetUpMethod(@NotNull PsiClass clazz) { for (PsiMethod each : clazz.getMethods()) { - if (AnnotationUtil.isAnnotated(each, "org.junit.Before", false)) return each; + if (AnnotationUtil.isAnnotated(each, JUnitUtil.BEFORE_ANNOTATION_NAME, false)) return each; } return null; } @@ -79,7 +79,7 @@ public class JUnit4Framework extends JavaTestFramework { @Override protected PsiMethod findTearDownMethod(@NotNull PsiClass clazz) { for (PsiMethod each : clazz.getMethods()) { - if (AnnotationUtil.isAnnotated(each, "org.junit.After", false)) return each; + if (AnnotationUtil.isAnnotated(each, JUnitUtil.AFTER_ANNOTATION_NAME, false)) return each; } return null; } @@ -102,7 +102,7 @@ public class JUnit4Framework extends JavaTestFramework { CommonBundle.getWarningTitle(), Messages.getWarningIcon()); if (exit == DialogWrapper.OK_EXIT_CODE) { - new AddAnnotationFix("org.junit.Before", existingMethod).invoke(existingMethod.getProject(), null, existingMethod.getContainingFile()); + new AddAnnotationFix(JUnitUtil.BEFORE_ANNOTATION_NAME, existingMethod).invoke(existingMethod.getProject(), null, existingMethod.getContainingFile()); return existingMethod; } } @@ -120,7 +120,7 @@ public class JUnit4Framework extends JavaTestFramework { @Override public boolean isIgnoredMethod(PsiElement element) { final PsiMethod testMethod = element instanceof PsiMethod ? JUnitUtil.getTestMethod(element) : null; - return testMethod != null && AnnotationUtil.isAnnotated(testMethod, Ignore.class.getName(), false); + return testMethod != null && AnnotationUtil.isAnnotated(testMethod, JUnitUtil.IGNORE_ANNOTATION, false); } @Override @@ -147,7 +147,7 @@ public class JUnit4Framework extends JavaTestFramework { @Override public boolean isParameterized(PsiClass clazz) { - final PsiAnnotation annotation = AnnotationUtil.findAnnotation(clazz, "org.junit.runner.RunWith"); + final PsiAnnotation annotation = AnnotationUtil.findAnnotation(clazz, JUnitUtil.RUN_WITH); if (annotation != null) { final PsiAnnotationMemberValue value = annotation.findAttributeValue(PsiAnnotation.DEFAULT_REFERENCED_METHOD_NAME); if (value instanceof PsiClassObjectAccessExpression) {