From: David ‘Bombe’ Roden Date: Fri, 26 Jul 2019 14:17:00 +0000 (+0200) Subject: 🐛 Register manually created core with event bus X-Git-Tag: v81^2~184 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=33b58cb4388ee7ca267470c0d883653e1a16dff4;p=Sone.git 🐛 Register manually created core with event bus --- 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) + } + }