IDEA-144665 (Incorrect 'tearDown() is not called from finally block' inspection)

This commit is contained in:
Bas Leijdekkers
2015-09-02 14:51:24 +02:00
parent 90f723e35e
commit 10d5db3598
2 changed files with 18 additions and 4 deletions
@@ -55,7 +55,7 @@ public class SuperTearDownInFinallyInspection extends BaseInspection {
return;
}
final PsiMethod method = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, true, PsiMember.class, PsiLambdaExpression.class);
if (method == null) {
if (method == null || !method.getName().equals("tearDown")) {
return;
}
final PsiClass containingClass = method.getContainingClass();
@@ -1,17 +1,19 @@
class SuperTearDownInFinally extends junit.framework.TestCase {
import junit.framework.TestCase;
class SuperTearDownInFinally extends TestCase {
public void tearDown() throws Exception {
super.<warning descr="'tearDown()' not called from 'finally' block">tearDown</warning>();
System.out.println();
}
}
class NoProblem extends junit.framework.TestCase {
class NoProblem extends TestCase {
public void tearDown() throws Exception {
super.tearDown();
}
}
class CalledInFinally extends junit.framework.TestCase {
class CalledInFinally extends TestCase {
public void tearDown() throws Exception {
try {
@@ -20,4 +22,16 @@ class CalledInFinally extends junit.framework.TestCase {
super.tearDown();
}
}
}
class SomeTest extends TestCase {
@Override
protected void setUp() throws Exception {
try {
super.setUp();
}
catch (Throwable t) {
super.tearDown(); // yellow code
}
}
public void test_something() {}
}