mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit 5: warn if repetitions is 0 or negative (IDEA-172093)
This commit is contained in:
+9
-4
@@ -22,12 +22,10 @@ import com.intellij.execution.junit.JUnitUtil
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion
|
||||
import com.intellij.openapi.projectRoots.JavaVersionService
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.JavaElementVisitor
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.*
|
||||
import com.siyeh.InspectionGadgetsBundle
|
||||
import com.siyeh.ig.junit.JUnitCommonClassNames
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils
|
||||
import org.jetbrains.annotations.Nls
|
||||
|
||||
class JUnit5MalformedRepeatedTestInspection : BaseJavaBatchLocalInspectionTool() {
|
||||
@@ -55,6 +53,13 @@ class JUnit5MalformedRepeatedTestInspection : BaseJavaBatchLocalInspectionTool()
|
||||
holder.registerProblem(testAnno, "Suspicious combination @Test and @RepeatedTest",
|
||||
DeleteElementFix(testAnno))
|
||||
}
|
||||
val repeatedNumber = repeatedAnno.findDeclaredAttributeValue("value")
|
||||
if (repeatedNumber is PsiExpression) {
|
||||
val constant = ExpressionUtils.computeConstantExpression(repeatedNumber)
|
||||
if (constant is Int && constant <= 0) {
|
||||
holder.registerProblem(repeatedNumber, "The number of repetitions must be greater than zero")
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
val repetitionInfo = JavaPsiFacade.getInstance(holder.project).findClass(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_REPETITION_INFO, file.resolveScope)
|
||||
|
||||
+2
-1
@@ -32,7 +32,7 @@ public class JUnit5MalformedRepeatedTest extends LightInspectionTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
addEnvironmentClass("package org.junit.jupiter.api;\n" +
|
||||
"public @interface RepeatedTest {}");
|
||||
"public @interface RepeatedTest {int value(); }");
|
||||
addEnvironmentClass("package org.junit.jupiter.api;\n" +
|
||||
"public @interface Test {}");
|
||||
addEnvironmentClass("package org.junit.jupiter.api;\n" +
|
||||
@@ -44,6 +44,7 @@ public class JUnit5MalformedRepeatedTest extends LightInspectionTestCase {
|
||||
}
|
||||
|
||||
public void testMalformed() { doTest(); }
|
||||
public void testPositiveRepetitions() { doTest(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
|
||||
@@ -12,10 +12,10 @@ class WithRepeatedInfoAndTest {
|
||||
}
|
||||
|
||||
class WithRepeated {
|
||||
@RepeatedTest()
|
||||
@RepeatedTest(1)
|
||||
void repeatedTestNoParams() { }
|
||||
|
||||
@RepeatedTest()
|
||||
@RepeatedTest(1)
|
||||
void repeatedTestWithRepetitionInfo(RepetitionInfo repetitionInfo) { }
|
||||
|
||||
@BeforeAll
|
||||
@@ -27,6 +27,6 @@ class WithRepeated {
|
||||
|
||||
class WithRepeatedAndTests {
|
||||
<warning descr="Suspicious combination @Test and @RepeatedTest">@Test</warning>
|
||||
@RepeatedTest()
|
||||
@RepeatedTest(1)
|
||||
void repeatedTestAndTest() { }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
class WithRepeated {
|
||||
@RepeatedTest(<warning descr="The number of repetitions must be greater than zero">-1</warning>)
|
||||
void repeatedTestNoParams() { }
|
||||
}
|
||||
Reference in New Issue
Block a user