🎨 Rename test method to be more specific
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / main / SoneModuleTest.kt
index 0b8ef04..526c089 100644 (file)
@@ -1,10 +1,13 @@
 package net.pterodactylus.sone.main
 
+import com.codahale.metrics.*
 import com.google.common.base.*
 import com.google.common.eventbus.*
 import com.google.inject.Guice.*
 import com.google.inject.name.Names.*
 import freenet.l10n.*
+import freenet.pluginmanager.*
+import net.pterodactylus.sone.core.*
 import net.pterodactylus.sone.database.*
 import net.pterodactylus.sone.database.memory.*
 import net.pterodactylus.sone.freenet.wot.*
@@ -13,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.*
@@ -33,7 +37,13 @@ class SoneModuleTest {
                whenever(l10n()).thenReturn(l10n)
        }
 
-       private val injector by lazy { createInjector(SoneModule(sonePlugin)) }
+       private val injector by lazy {
+               createInjector(
+                               SoneModule(sonePlugin, EventBus()),
+                               FreenetInterface::class.isProvidedByDeepMock(),
+                               PluginRespirator::class.isProvidedByDeepMock()
+               )
+       }
 
        @AfterTest
        fun removePropertiesFromCurrentDirectory() {
@@ -92,6 +102,12 @@ class SoneModuleTest {
        }
 
        @Test
+       fun `show version information debug information flag is read from config`() {
+               File(currentDir, "sone.properties").writeText("Debug/ShowVersionInformation=true")
+               assertThat(injector.getInstance<Core>().debugInformation.showVersionInformation, equalTo(true))
+       }
+
+       @Test
        fun `event bus is bound`() {
                assertThat(injector.getInstance<EventBus>(), notNullValue())
        }
@@ -175,4 +191,35 @@ class SoneModuleTest {
                assertThat(testObject.ref.get(), sameInstance(event))
        }
 
+       @Test
+       fun `core is created as singleton`() {
+               val firstCore = injector.getInstance<Core>()
+               val secondCore = injector.getInstance<Core>()
+               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)
+       }
+
+       @Test
+       fun `metrics registry can be created`() {
+               assertThat(injector.getInstance<MetricRegistry>(), notNullValue())
+       }
+
+       @Test
+       fun `metrics registry is created as singleton`() {
+               val firstMetricRegistry = injector.getInstance<MetricRegistry>()
+               val secondMetricRegistry = injector.getInstance<MetricRegistry>()
+               assertThat(firstMetricRegistry, sameInstance(secondMetricRegistry))
+       }
+
 }