diff --git a/plugins/junit/src/com/intellij/execution/junit/codeInsight/JUnit5MalformedRepeatedTestInspection.kt b/plugins/junit/src/com/intellij/execution/junit/codeInsight/JUnit5MalformedRepeatedTestInspection.kt index a1f34f293e80..66885f5850d7 100644 --- a/plugins/junit/src/com/intellij/execution/junit/codeInsight/JUnit5MalformedRepeatedTestInspection.kt +++ b/plugins/junit/src/com/intellij/execution/junit/codeInsight/JUnit5MalformedRepeatedTestInspection.kt @@ -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 { diff --git a/plugins/junit/test/com/intellij/execution/junit/codeInsight/JUnit5MalformedRepeatedTest.java b/plugins/junit/test/com/intellij/execution/junit/codeInsight/JUnit5MalformedRepeatedTest.java index a7b321ab1d01..a752fa905b26 100644 --- a/plugins/junit/test/com/intellij/execution/junit/codeInsight/JUnit5MalformedRepeatedTest.java +++ b/plugins/junit/test/com/intellij/execution/junit/codeInsight/JUnit5MalformedRepeatedTest.java @@ -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(); } diff --git a/plugins/junit/testData/codeInsight/malformedRepeated/Malformed.java b/plugins/junit/testData/codeInsight/malformedRepeated/Malformed.java index 7a75fe770d4f..fd085ec04c1b 100644 --- a/plugins/junit/testData/codeInsight/malformedRepeated/Malformed.java +++ b/plugins/junit/testData/codeInsight/malformedRepeated/Malformed.java @@ -30,3 +30,8 @@ class WithRepeatedAndTests { @RepeatedTest(1) void repeatedTestAndTest() { } } + +class WithParameterized { + @ParameterizedTest + void testaccidentalRepetitionInfo(Object s, RepetitionInfo repetitionInfo) { } +} \ No newline at end of file