From adb26fa1e99701b0f9ed5c561c4e40b83e82ba5b Mon Sep 17 00:00:00 2001 From: Robert Novotny Date: Wed, 31 Jul 2024 10:10:42 +0200 Subject: [PATCH] Extract common EP behavior into parent class --- .../verifiers/BaseExtensionPointTest.kt | 22 +++++++++++++++++++ .../verifiers/LanguageBundleEpVerifierTest.kt | 21 +----------------- ...erviceExtensionPointPreloadVerifierTest.kt | 21 ++---------------- ...WidgetFactoryExtensionPointVerifierTest.kt | 21 ++---------------- 4 files changed, 27 insertions(+), 58 deletions(-) create mode 100644 intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/BaseExtensionPointTest.kt diff --git a/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/BaseExtensionPointTest.kt b/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/BaseExtensionPointTest.kt new file mode 100644 index 0000000000..5383c2f143 --- /dev/null +++ b/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/BaseExtensionPointTest.kt @@ -0,0 +1,22 @@ +package com.jetbrains.plugin.structure.intellij.verifiers + +import com.jetbrains.plugin.structure.base.problems.PluginProblem +import com.jetbrains.plugin.structure.mocks.SimpleProblemRegistrar +import org.junit.Before + +internal const val PLUGIN_ID = "com.example.thirdparty" +internal const val PLUGIN_VENDOR = "PluginIndustries s.r.o." +internal const val JETBRAINS_PLUGIN_VENDOR = "JetBrains" + +abstract class BaseExtensionPointTest(val verifier: V) { + + protected val problemRegistrar = SimpleProblemRegistrar() + + protected val problems: List + get() = problemRegistrar.problems + + @Before + fun setUp() { + problemRegistrar.reset() + } +} \ No newline at end of file diff --git a/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/LanguageBundleEpVerifierTest.kt b/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/LanguageBundleEpVerifierTest.kt index aad23c63e5..41e4d0cbd5 100644 --- a/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/LanguageBundleEpVerifierTest.kt +++ b/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/LanguageBundleEpVerifierTest.kt @@ -1,32 +1,13 @@ package com.jetbrains.plugin.structure.intellij.verifiers -import com.jetbrains.plugin.structure.base.problems.PluginProblem import com.jetbrains.plugin.structure.intellij.plugin.IdePluginImpl import com.jetbrains.plugin.structure.mocks.MockExtension import org.junit.Assert.assertEquals -import org.junit.Before import org.junit.Test -private const val PLUGIN_ID = "com.example.thirdparty" -private const val PLUGIN_VENDOR = "PluginIndustries s.r.o." -private const val JETBRAINS_PLUGIN_VENDOR = "JetBrains" private const val MESSAGE_TEMPLATE = "The extension point in the element is internal and must be used by JetBrains only." - -class LanguageBundleEpVerifierTest { - private lateinit var verifier: LanguageBundleExtensionPointVerifier - - private lateinit var problems: MutableList - - private val problemRegistrar = ProblemRegistrar { - problems += it - } - - @Before - fun setUp() { - verifier = LanguageBundleExtensionPointVerifier() - problems = mutableListOf() - } +class LanguageBundleEpVerifierTest : BaseExtensionPointTest(LanguageBundleExtensionPointVerifier()) { @Test fun `plugin is not allowed to use languageBundle EP`() { diff --git a/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/ServiceExtensionPointPreloadVerifierTest.kt b/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/ServiceExtensionPointPreloadVerifierTest.kt index d5b77edb64..5f7c8111f8 100644 --- a/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/ServiceExtensionPointPreloadVerifierTest.kt +++ b/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/ServiceExtensionPointPreloadVerifierTest.kt @@ -1,34 +1,17 @@ package com.jetbrains.plugin.structure.intellij.verifiers -import com.jetbrains.plugin.structure.base.problems.PluginProblem import com.jetbrains.plugin.structure.intellij.plugin.IdePluginContentDescriptor.* import com.jetbrains.plugin.structure.intellij.plugin.IdePluginImpl import org.junit.Assert import org.junit.Assert.assertEquals -import org.junit.Before import org.junit.Test -private const val PLUGIN_ID = "com.example.thirdparty" -private const val PLUGIN_VENDOR = "PluginIndustries s.r.o." private const val MESSAGE_TEMPLATE = "Service preloading is deprecated in the <%s> element. Remove the 'preload' " + "attribute and migrate to listeners, see https://plugins.jetbrains.com/docs/intellij/plugin-listeners.html." -class ServiceExtensionPointPreloadVerifierTest { - private lateinit var verifier: ServiceExtensionPointPreloadVerifier - - private lateinit var problems: MutableList - - private val problemRegistrar = ProblemRegistrar { - problems += it - } - - @Before - fun setUp() { - verifier = ServiceExtensionPointPreloadVerifier() - problems = mutableListOf() - } - +class ServiceExtensionPointPreloadVerifierTest : + BaseExtensionPointTest(ServiceExtensionPointPreloadVerifier()) { @Test fun `has a single project service that is preloaded`() { diff --git a/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/StatusBarWidgetFactoryExtensionPointVerifierTest.kt b/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/StatusBarWidgetFactoryExtensionPointVerifierTest.kt index c454de54be..8b818c842f 100644 --- a/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/StatusBarWidgetFactoryExtensionPointVerifierTest.kt +++ b/intellij-plugin-structure/tests/src/test/kotlin/com/jetbrains/plugin/structure/intellij/verifiers/StatusBarWidgetFactoryExtensionPointVerifierTest.kt @@ -1,35 +1,18 @@ package com.jetbrains.plugin.structure.intellij.verifiers -import com.jetbrains.plugin.structure.base.problems.PluginProblem import com.jetbrains.plugin.structure.intellij.plugin.IdePluginImpl import org.jdom2.Element import org.junit.Assert -import org.junit.Before import org.junit.Test -private const val PLUGIN_ID = "com.example.thirdparty" -private const val PLUGIN_VENDOR = "PluginIndustries s.r.o." private const val EP_IMPLEMENTATION = "com.example.MyStatusBarWidgetFactory" private const val MESSAGE_TEMPLATE = "The extension point in the element must have " + "'id' attribute set with the same value returned from the getId() method of the $EP_IMPLEMENTATION implementation." -class StatusBarWidgetFactoryExtensionPointVerifierTest { - private lateinit var verifier: StatusBarWidgetFactoryExtensionPointVerifier - - private lateinit var problems: MutableList - - private val problemRegistrar = ProblemRegistrar { - problems += it - } - - @Before - fun setUp() { - verifier = StatusBarWidgetFactoryExtensionPointVerifier() - problems = mutableListOf() - } - +class StatusBarWidgetFactoryExtensionPointVerifierTest : + BaseExtensionPointTest(StatusBarWidgetFactoryExtensionPointVerifier()) { @Test fun `status bar widget factory extension does not declare ID`() {