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.*;
@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);
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")
.getValue(null)
?.let { DebugLoaders(it) }
}
- val eventBus = EventBus()
bind(Configuration::class.java).toInstance(configuration)
bind(EventBus::class.java).toInstance(eventBus)
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)
}
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.*
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() {
assertThat(secondCore, sameInstance(firstCore))
}
+ @Test
+ fun `core is registered with event bus`() {
+ val eventBus = mock<EventBus>()
+ val injector = createInjector(
+ SoneModule(sonePlugin, eventBus),
+ FreenetInterface::class.isProvidedByDeepMock(),
+ PluginRespirator::class.isProvidedByDeepMock()
+ )
+ val core = injector.getInstance<Core>()
+ verify(eventBus).register(core)
+ }
+
}