Skip to content

Commit

Permalink
Extract common EP behavior into parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
novotnyr committed Jul 31, 2024
1 parent 668a99e commit adb26fa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -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<V : Any>(val verifier: V) {

protected val problemRegistrar = SimpleProblemRegistrar()

protected val problems: List<PluginProblem>
get() = problemRegistrar.problems

@Before
fun setUp() {
problemRegistrar.reset()
}
}
Original file line number Diff line number Diff line change
@@ -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 <com.intellij.languageBundle> element is internal and must be used by JetBrains only."


class LanguageBundleEpVerifierTest {
private lateinit var verifier: LanguageBundleExtensionPointVerifier

private lateinit var problems: MutableList<PluginProblem>

private val problemRegistrar = ProblemRegistrar {
problems += it
}

@Before
fun setUp() {
verifier = LanguageBundleExtensionPointVerifier()
problems = mutableListOf()
}
class LanguageBundleEpVerifierTest : BaseExtensionPointTest<LanguageBundleExtensionPointVerifier>(LanguageBundleExtensionPointVerifier()) {

@Test
fun `plugin is not allowed to use languageBundle EP`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PluginProblem>

private val problemRegistrar = ProblemRegistrar {
problems += it
}

@Before
fun setUp() {
verifier = ServiceExtensionPointPreloadVerifier()
problems = mutableListOf()
}

class ServiceExtensionPointPreloadVerifierTest :
BaseExtensionPointTest<ServiceExtensionPointPreloadVerifier>(ServiceExtensionPointPreloadVerifier()) {

@Test
fun `has a single project service that is preloaded`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <com.intellij.statusBarWidgetFactory> 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<PluginProblem>

private val problemRegistrar = ProblemRegistrar {
problems += it
}

@Before
fun setUp() {
verifier = StatusBarWidgetFactoryExtensionPointVerifier()
problems = mutableListOf()
}

class StatusBarWidgetFactoryExtensionPointVerifierTest :
BaseExtensionPointTest<StatusBarWidgetFactoryExtensionPointVerifier>(StatusBarWidgetFactoryExtensionPointVerifier()) {

@Test
fun `status bar widget factory extension does not declare ID`() {
Expand Down

0 comments on commit adb26fa

Please sign in to comment.