mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit: warn about RepetitionInfo on in parameterized test (IDEA-175992)
This commit is contained in:
+7
-2
@@ -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 {
|
||||
|
||||
+2
@@ -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) { }
|
||||
}
|
||||
Reference in New Issue
Block a user