From 33b58cb4388ee7ca267470c0d883653e1a16dff4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 26 Jul 2019 16:17:00 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=90=9B=20Register=20manually=20created=20c?= =?utf8?q?ore=20with=20event=20bus?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/main/SonePlugin.java | 3 ++- .../net/pterodactylus/sone/main/SoneModule.kt | 5 ++--- .../net/pterodactylus/sone/main/SoneModuleTest.kt | 25 +++++++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index e82e771..540f3ac 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -22,6 +22,7 @@ import static java.util.logging.Logger.*; import java.util.logging.Logger; import java.util.logging.*; +import com.google.common.eventbus.*; import net.pterodactylus.sone.core.*; import net.pterodactylus.sone.fcp.*; import net.pterodactylus.sone.freenet.wot.*; @@ -205,7 +206,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr @VisibleForTesting protected Injector createInjector() { FreenetModule freenetModule = new FreenetModule(pluginRespirator); - AbstractModule soneModule = new SoneModule(this); + AbstractModule soneModule = new SoneModule(this, new EventBus()); Module webInterfaceModule = new WebInterfaceModule(); return createInjector(freenetModule, soneModule, webInterfaceModule); diff --git a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt index 66cd29a..31cc54a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt @@ -16,7 +16,7 @@ import net.pterodactylus.util.config.ConfigurationException import net.pterodactylus.util.version.Version import java.io.* -class SoneModule(private val sonePlugin: SonePlugin) : AbstractModule() { +open class SoneModule(private val sonePlugin: SonePlugin, private val eventBus: EventBus) : AbstractModule() { override fun configure() { val sonePropertiesFile = File("sone.properties") @@ -37,7 +37,6 @@ class SoneModule(private val sonePlugin: SonePlugin) : AbstractModule() { .getValue(null) ?.let { DebugLoaders(it) } } - val eventBus = EventBus() bind(Configuration::class.java).toInstance(configuration) bind(EventBus::class.java).toInstance(eventBus) @@ -66,7 +65,7 @@ class SoneModule(private val sonePlugin: SonePlugin) : AbstractModule() { fun getCore(configuration: Configuration, freenetInterface: FreenetInterface, identityManager: IdentityManager, soneDownloader: SoneDownloader, imageInserter: ImageInserter, updateChecker: UpdateChecker, webOfTrustUpdater: WebOfTrustUpdater, eventBus: EventBus, database: Database) = Core(configuration, freenetInterface, identityManager, soneDownloader, imageInserter, updateChecker, webOfTrustUpdater, eventBus, database).apply { debugInformation.showVersionInformation = configuration.getBooleanValue("Debug/ShowVersionInformation").getValue(false) - } + }.also(eventBus::register) } diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt index d928214..6cac0a8 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt @@ -16,6 +16,7 @@ import net.pterodactylus.util.config.* import net.pterodactylus.util.version.Version import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* +import org.mockito.Mockito.* import java.io.* import java.util.concurrent.atomic.* import kotlin.test.* @@ -36,11 +37,13 @@ class SoneModuleTest { whenever(l10n()).thenReturn(l10n) } - private val injector by lazy { createInjector( - SoneModule(sonePlugin), - FreenetInterface::class.isProvidedByDeepMock(), - PluginRespirator::class.isProvidedByDeepMock() - ) } + private val injector by lazy { + createInjector( + SoneModule(sonePlugin, EventBus()), + FreenetInterface::class.isProvidedByDeepMock(), + PluginRespirator::class.isProvidedByDeepMock() + ) + } @AfterTest fun removePropertiesFromCurrentDirectory() { @@ -195,4 +198,16 @@ class SoneModuleTest { assertThat(secondCore, sameInstance(firstCore)) } + @Test + fun `core is registered with event bus`() { + val eventBus = mock() + val injector = createInjector( + SoneModule(sonePlugin, eventBus), + FreenetInterface::class.isProvidedByDeepMock(), + PluginRespirator::class.isProvidedByDeepMock() + ) + val core = injector.getInstance() + verify(eventBus).register(core) + } + } -- 2.7.4