treat classes with before/after methods as test classes for bad declared exceptions (IDEA-112537)

This commit is contained in:
Anna Kozlova
2013-08-26 14:02:44 +04:00
parent 4be2bcf4f0
commit d7ecb44d17
3 changed files with 26 additions and 6 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -35,4 +35,11 @@ public abstract class TestFrameworks {
@Nullable
public abstract PsiMethod findSetUpMethod(PsiClass psiClass);
@Nullable
public abstract PsiMethod findTearDownMethod(PsiClass psiClass);
public boolean isTestOrConfig(PsiClass psiClass) {
return isTestClass(psiClass) || findTearDownMethod(psiClass) != null || findTearDownMethod(psiClass) != null;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -76,4 +76,19 @@ public class TestFrameworksImpl extends TestFrameworks {
}
return null;
}
@Override
@Nullable
public PsiMethod findTearDownMethod(final PsiClass psiClass) {
final TestFramework[] testFrameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME);
for (TestFramework framework : testFrameworks) {
if (framework.isTestClass(psiClass)) {
final PsiMethod setUpMethod = (PsiMethod)framework.findTearDownMethod(psiClass);
if (setUpMethod != null) {
return setUpMethod;
}
}
}
return null;
}
}
@@ -133,10 +133,8 @@ public class BadExceptionDeclaredInspection extends BaseInspection {
super.visitMethod(method);
if (ignoreTestCases) {
final PsiClass containingClass = method.getContainingClass();
if (containingClass != null && TestFrameworks.getInstance().isTestClass(containingClass)) {
return;
}
if (TestUtils.isJUnitTestMethod(method)) {
final TestFrameworks testFrameworks = TestFrameworks.getInstance();
if (containingClass != null && testFrameworks.isTestOrConfig(containingClass)) {
return;
}
}