IG: don't warn on test classes annotated with @RunWith (IDEA-163266)

This commit is contained in:
Bas Leijdekkers
2016-11-03 15:12:05 +01:00
parent 94fbc85606
commit e062b9881e
3 changed files with 30 additions and 4 deletions
@@ -77,7 +77,10 @@ public class TestMethodIsPublicVoidNoArgInspectionBase extends BaseInspection {
if (!TestUtils.isJUnit3TestMethod(method) && !TestUtils.isJUnit4TestMethod(method)) {
return;
}
final PsiType returnType = method.getReturnType();
final PsiClass containingClass = method.getContainingClass();
if (containingClass == null || AnnotationUtil.isAnnotated(containingClass, TestUtils.RUN_WITH, true)) {
return;
}
final PsiParameterList parameterList = method.getParameterList();
if (method.hasModifierProperty(PsiModifier.STATIC)) {
registerMethodError(method, Problem.STATIC, method);
@@ -97,6 +100,7 @@ public class TestMethodIsPublicVoidNoArgInspectionBase extends BaseInspection {
return;
}
}
final PsiType returnType = method.getReturnType();
if (!PsiType.VOID.equals(returnType) || !method.hasModifierProperty(PsiModifier.PUBLIC)) {
registerMethodError(method, Problem.NOT_PUBLIC_VOID, method);
}
@@ -0,0 +1,9 @@
@org.junit.runner.RunWith(org.junit.runner.Runner.class)
class JUnit4RunWith {
@org.junit.Test
public int testMe(int i) {
return -1;
}
}
@@ -26,6 +26,7 @@ public class TestMethodIsPublicVoidNoArgInspectionTest extends LightInspectionTe
public void testJUnit3TestMethodIsPublicVoidNoArg() { doTest(); }
public void testJUnit4TestMethodIsPublicVoidNoArg() { doTest(); }
public void testJUnit4RunWith() { doTest(); }
@Nullable
@Override
@@ -40,11 +41,23 @@ public class TestMethodIsPublicVoidNoArgInspectionTest extends LightInspectionTe
"public @interface Test {\n" +
" java.lang.Class<? extends java.lang.Throwable> expected() default org.junit.Test.None.class;" +
"}",
"package org.junit.runner;" +
"@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" +
"@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE})\n" +
"@java.lang.annotation.Inherited\n" +
"public @interface RunWith {\n" +
" Class<? extends Runner> value();\n" +
"}",
"package org.junit.runner;" +
"public abstract class Runner {}",
"package junit.framework;" +
"public abstract class TestCase {}",
"package mockit;" +
"@Retention(value=RUNTIME) @Target(value={FIELD,PARAMETER})" +
"public @interface Mocked {}"};
"package mockit;" +
"@Retention(value=RUNTIME) @Target(value={FIELD,PARAMETER})" +
"public @interface Mocked {}"};
}
}