From d7ecb44d17bf176f453a65202686461860ef2701 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 26 Aug 2013 13:25:04 +0400 Subject: [PATCH] treat classes with before/after methods as test classes for bad declared exceptions (IDEA-112537) --- .../intellij/codeInsight/TestFrameworks.java | 9 ++++++++- .../codeInsight/TestFrameworksImpl.java | 17 ++++++++++++++++- .../BadExceptionDeclaredInspection.java | 6 ++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/java/java-psi-api/src/com/intellij/codeInsight/TestFrameworks.java b/java/java-psi-api/src/com/intellij/codeInsight/TestFrameworks.java index 9f7e02457f4a..33ee86b3540a 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/TestFrameworks.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/TestFrameworks.java @@ -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; + } } diff --git a/java/java-psi-impl/src/com/intellij/codeInsight/TestFrameworksImpl.java b/java/java-psi-impl/src/com/intellij/codeInsight/TestFrameworksImpl.java index 08c7cd23d8dc..0dfbea7a2b68 100644 --- a/java/java-psi-impl/src/com/intellij/codeInsight/TestFrameworksImpl.java +++ b/java/java-psi-impl/src/com/intellij/codeInsight/TestFrameworksImpl.java @@ -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; + } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/BadExceptionDeclaredInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/BadExceptionDeclaredInspection.java index 98357a2e5020..5ce1f400d165 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/BadExceptionDeclaredInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/errorhandling/BadExceptionDeclaredInspection.java @@ -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; } }