diff --git a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java index 20f7281ef1c5..2ece275f7282 100644 --- a/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java +++ b/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java @@ -24,6 +24,7 @@ import com.intellij.testIntegration.JavaTestFramework; import com.intellij.testIntegration.TestFramework; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; +import com.siyeh.ig.junit.JUnitCommonClassNames; import com.siyeh.ig.psiutils.TestUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -76,7 +77,8 @@ public final class JUnitUtil { private static final Collection CONFIGURATIONS_ANNOTATION_NAME = List.of(DATA_POINT, AFTER_ANNOTATION_NAME, BEFORE_ANNOTATION_NAME, AFTER_EACH_ANNOTATION_NAME, BEFORE_EACH_ANNOTATION_NAME, - AFTER_CLASS_ANNOTATION_NAME, BEFORE_CLASS_ANNOTATION_NAME, BEFORE_ALL_ANNOTATION_NAME, AFTER_ALL_ANNOTATION_NAME, RULE_ANNOTATION); + AFTER_CLASS_ANNOTATION_NAME, BEFORE_CLASS_ANNOTATION_NAME, BEFORE_ALL_ANNOTATION_NAME, AFTER_ALL_ANNOTATION_NAME, RULE_ANNOTATION, + JUnitCommonClassNames.ORG_JUNIT_PLATFORM_SUITE_API_AFTERSUITE, JUnitCommonClassNames.ORG_JUNIT_PLATFORM_SUITE_API_BEFORESUITE); public static final String PARAMETERIZED_CLASS_NAME = "org.junit.runners.Parameterized"; public static final String SUITE_CLASS_NAME = "org.junit.runners.Suite"; @@ -135,10 +137,10 @@ public final class JUnitUtil { if (psiMethod.isConstructor()) return false; if (psiMethod.hasModifierProperty(PsiModifier.PRIVATE)) return false; if (isTestAnnotated(psiMethod, true)) return !psiMethod.hasModifierProperty(PsiModifier.STATIC); + if (AnnotationUtil.isAnnotated(psiMethod, CONFIGURATIONS_ANNOTATION_NAME, 0)) return false; if (aClass != null && MetaAnnotationUtil.isMetaAnnotatedInHierarchy(aClass, Collections.singletonList(CUSTOM_TESTABLE_ANNOTATION))) return true; if (!psiMethod.hasModifierProperty(PsiModifier.PUBLIC)) return false; if (psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) return false; - if (AnnotationUtil.isAnnotated(psiMethod, CONFIGURATIONS_ANNOTATION_NAME, 0)) return false; if (checkClass && checkRunWith) { PsiAnnotation annotation = getRunWithAnnotation(aClass); if (annotation != null) { diff --git a/java/java-analysis-impl/src/com/siyeh/ig/junit/JUnitCommonClassNames.java b/java/java-analysis-impl/src/com/siyeh/ig/junit/JUnitCommonClassNames.java index 89fac8c1d913..2b3d1228eca4 100644 --- a/java/java-analysis-impl/src/com/siyeh/ig/junit/JUnitCommonClassNames.java +++ b/java/java-analysis-impl/src/com/siyeh/ig/junit/JUnitCommonClassNames.java @@ -85,6 +85,8 @@ public final @NonNls class JUnitCommonClassNames { public static final String ORG_JUNIT_EXPERIMENTAL_RUNNERS_ENCLOSED = "org.junit.experimental.runners.Enclosed"; public static final String ORG_JUNIT_JUPITER_API_IO_TEMPDIR = "org.junit.jupiter.api.io.TempDir"; public static final String ORG_JUNIT_PLATFORM_SUITE_API_SUITE = "org.junit.platform.suite.api.Suite"; + public static final String ORG_JUNIT_PLATFORM_SUITE_API_AFTERSUITE = "org.junit.platform.suite.api.AfterSuite"; + public static final String ORG_JUNIT_PLATFORM_SUITE_API_BEFORESUITE = "org.junit.platform.suite.api.BeforeSuite"; // junit 6 public static final String ORG_JUNIT_JUPITER_API_METHOD_ORDERER_DEFAULT = "org.junit.jupiter.api.MethodOrderer.Default"; } diff --git a/jvm/jvm-analysis-internal-testFramework/src/com/intellij/jvm/analysis/internal/testFramework/test/TestMethodWithoutAssertionInspectionTestBase.kt b/jvm/jvm-analysis-internal-testFramework/src/com/intellij/jvm/analysis/internal/testFramework/test/TestMethodWithoutAssertionInspectionTestBase.kt index f178553a49fc..813ab87e9d49 100644 --- a/jvm/jvm-analysis-internal-testFramework/src/com/intellij/jvm/analysis/internal/testFramework/test/TestMethodWithoutAssertionInspectionTestBase.kt +++ b/jvm/jvm-analysis-internal-testFramework/src/com/intellij/jvm/analysis/internal/testFramework/test/TestMethodWithoutAssertionInspectionTestBase.kt @@ -22,6 +22,7 @@ abstract class TestMethodWithoutAssertionInspectionTestBase : JvmInspectionTestB model.addJUnit3Library() model.addJUnit4Library() model.addJUnit5Library() + model.addJUnitSuiteLibrary() model.addMockKLibrary() model.addAssertJLibrary() } diff --git a/jvm/jvm-analysis-internal-testFramework/src/com/intellij/jvm/analysis/internal/testFramework/test/testFrameWorkSetup.kt b/jvm/jvm-analysis-internal-testFramework/src/com/intellij/jvm/analysis/internal/testFramework/test/testFrameWorkSetup.kt index 00599314b09b..430d18df638c 100644 --- a/jvm/jvm-analysis-internal-testFramework/src/com/intellij/jvm/analysis/internal/testFramework/test/testFrameWorkSetup.kt +++ b/jvm/jvm-analysis-internal-testFramework/src/com/intellij/jvm/analysis/internal/testFramework/test/testFrameWorkSetup.kt @@ -34,6 +34,10 @@ internal fun ModifiableRootModel.addJUnit5Library(version: String = "5.9.1") { MavenDependencyUtil.addFromMaven(this, "org.junit.jupiter:junit-jupiter-params:$version") } +internal fun ModifiableRootModel.addJUnitSuiteLibrary(version: String = "6.0.0") { + MavenDependencyUtil.addFromMaven(this, "org.junit.platform:junit-platform-suite-api:$version") +} + internal fun ModifiableRootModel.addAssertJLibrary(version: String = "3.24.2") { MavenDependencyUtil.addFromMaven(this, "org.assertj:assertj-core:$version") } diff --git a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/test/JavaTestMethodWithoutAssertionInspectionTest.kt b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/test/JavaTestMethodWithoutAssertionInspectionTest.kt index d11a3717038c..6d201ab2dd8c 100644 --- a/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/test/JavaTestMethodWithoutAssertionInspectionTest.kt +++ b/jvm/jvm-analysis-java-tests/testSrc/com/intellij/codeInspection/tests/java/test/JavaTestMethodWithoutAssertionInspectionTest.kt @@ -108,4 +108,23 @@ class JavaTestMethodWithoutAssertionInspectionTest : TestMethodWithoutAssertionI } """.trimIndent(), "SimpleTest") } + + fun `test no highlighting on before and after suite`() { + myFixture.testHighlighting(JvmLanguage.JAVA, """ + import org.junit.platform.suite.api.AfterSuite; + import org.junit.platform.suite.api.BeforeSuite; + import org.junit.platform.suite.api.SelectPackages; + import org.junit.platform.suite.api.Suite; + + @Suite + @SelectPackages("example") + class BeforeAndAfterSuiteDemo { + @BeforeSuite + static void beforeSuite() { } + + @AfterSuite + static void afterSuite() { } + } + """.trimIndent(), "SimpleTest") + } } \ No newline at end of file