junit: warn about RepetitionInfo on in parameterized test (IDEA-175992)

This commit is contained in:
Anna.Kozlova
2017-07-20 18:56:14 +02:00
parent 6d8265fbdc
commit edf927424e
3 changed files with 14 additions and 2 deletions
@@ -31,6 +31,11 @@ import com.siyeh.ig.psiutils.ExpressionUtils
import org.jetbrains.annotations.Nls
class JUnit5MalformedRepeatedTestInspection : BaseJavaBatchLocalInspectionTool() {
object Annotations {
val NON_REPEATED_ANNOTATIONS = listOf(JUnitUtil.TEST5_ANNOTATION,
JUnitUtil.TEST5_FACTORY_ANNOTATION,
JUnitCommonClassNames.ORG_JUNIT_JUPITER_PARAMS_PARAMETERIZED_TEST)
}
@Nls
override fun getDisplayName(): String {
@@ -66,9 +71,9 @@ class JUnit5MalformedRepeatedTestInspection : BaseJavaBatchLocalInspectionTool()
else {
val repetitionInfo = JavaPsiFacade.getInstance(holder.project).findClass(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_REPETITION_INFO, file.resolveScope)
val repetitionType = JavaPsiFacade.getElementFactory(holder.project).createType(repetitionInfo!!)
val repetitionInfoParam = method.parameterList.parameters.find { it.type.isAssignableFrom(repetitionType) }
val repetitionInfoParam = method.parameterList.parameters.find { it.type == repetitionType }
if (repetitionInfoParam != null) {
if (MetaAnnotationUtil.isMetaAnnotated(method, JUnitUtil.TEST5_JUPITER_ANNOTATIONS)) {
if (MetaAnnotationUtil.isMetaAnnotated(method, Annotations.NON_REPEATED_ANNOTATIONS)) {
holder.registerProblem(repetitionInfoParam.nameIdentifier ?: repetitionInfoParam, "RepetitionInfo is injected for @RepeatedTest only")
}
else {
@@ -41,6 +41,8 @@ public class JUnit5MalformedRepeatedTest extends LightInspectionTestCase {
"public @interface BeforeEach {}");
addEnvironmentClass("package org.junit.jupiter.api;\n" +
"public interface RepetitionInfo {}");
addEnvironmentClass("package org.junit.jupiter.api;\n" +
"public @interface ParameterizedTest {}");
}
public void testMalformed() { doTest(); }
@@ -30,3 +30,8 @@ class WithRepeatedAndTests {
@RepeatedTest(1)
void repeatedTestAndTest() { }
}
class WithParameterized {
@ParameterizedTest
void testaccidentalRepetitionInfo(Object s, RepetitionInfo repetitionInfo) { }
}