From 0685ecc3d5cfea1a78466652ed06eb9ef68c35f9 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 9 Mar 2020 17:15:21 +0100 Subject: [PATCH] Add test for listeners in optional dependencies GitOrigin-RevId: 4ca7ee503b22dcef3ead7c9f7a00d3f1c1eb7f59 --- .../ide/plugins/DynamicPluginsTest.kt | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/platform/platform-tests/testSrc/com/intellij/ide/plugins/DynamicPluginsTest.kt b/platform/platform-tests/testSrc/com/intellij/ide/plugins/DynamicPluginsTest.kt index 0354463ab6c9..f6a5f0d01415 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/plugins/DynamicPluginsTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ide/plugins/DynamicPluginsTest.kt @@ -55,6 +55,7 @@ class DynamicPluginsTest { val projectRule = ProjectRule() val receivedNotifications = mutableListOf() + val receivedNotifications2 = mutableListOf() } @Rule @@ -376,6 +377,55 @@ class DynamicPluginsTest { } } + @Test + fun loadOptionalDependencyListener() { + receivedNotifications.clear() + receivedNotifications2.clear() + + val plugin1Disposable = loadPluginWithOptionalDependency( + """ + + foo + bar + + + + + """, + """ + + + + + + """) + try { + ApplicationManager.getApplication().messageBus.syncPublisher(UISettingsListener.TOPIC).uiSettingsChanged(UISettings()) + assertThat(receivedNotifications).hasSize(1) + + val plugin2Disposable = loadPluginWithText(""" + + bar + + """.trimIndent(), DynamicPluginsTest::class.java.classLoader) + try { + ApplicationManager.getApplication().messageBus.syncPublisher(UISettingsListener.TOPIC).uiSettingsChanged(UISettings()) + assertThat(receivedNotifications).hasSize(2) + assertThat(receivedNotifications2).hasSize(1) + } + finally { + Disposer.dispose(plugin2Disposable) + } + + ApplicationManager.getApplication().messageBus.syncPublisher(UISettingsListener.TOPIC).uiSettingsChanged(UISettings()) + assertThat(receivedNotifications).hasSize(3) + assertThat(receivedNotifications2).hasSize(1) + } + finally { + Disposer.dispose(plugin1Disposable) + } + } + @Test fun testProjectService() { val project = projectRule.project @@ -508,6 +558,12 @@ class DynamicPluginsTest { } } + private class MyUISettingsListener2 : UISettingsListener { + override fun uiSettingsChanged(uiSettings: UISettings) { + receivedNotifications2.add(uiSettings) + } + } + private data class MyPersistentState(@Attribute var stateData: String? = "") @State(name = "MyTestState", storages = [Storage("other.xml")], allowLoadInTests = true)