🚧 Make facade injectable instead of plugin respirator
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 27 Oct 2019 16:18:32 +0000 (17:18 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 27 Oct 2019 16:31:26 +0000 (17:31 +0100)
src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt
src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt
src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt

index 9b5fa2e..9fff176 100644 (file)
@@ -5,6 +5,7 @@ import freenet.client.*
 import freenet.clients.http.*
 import freenet.node.*
 import freenet.pluginmanager.*
+import net.pterodactylus.sone.freenet.plugin.*
 import javax.inject.Provider
 import javax.inject.Singleton
 
@@ -14,7 +15,7 @@ import javax.inject.Singleton
 class FreenetModule(private val pluginRespirator: PluginRespirator) : Module {
 
        override fun configure(binder: Binder): Unit = binder.run {
-               bind(PluginRespirator::class.java).toProvider(Provider<PluginRespirator> { pluginRespirator })
+               bind(PluginRespiratorFacade::class.java).toProvider(Provider { FredPluginRespiratorFacade(pluginRespirator) }).`in`(Singleton::class.java)
                pluginRespirator.node!!.let { node -> bind(Node::class.java).toProvider(Provider<Node> { node }) }
                bind(HighLevelSimpleClient::class.java).toProvider(Provider<HighLevelSimpleClient> { pluginRespirator.hlSimpleClient!! })
                bind(ToadletContainer::class.java).toProvider(Provider<ToadletContainer> { pluginRespirator.toadletContainer })
index 2f55d52..32d2ca4 100644 (file)
@@ -5,10 +5,13 @@ import freenet.client.*
 import freenet.clients.http.*
 import freenet.node.*
 import freenet.pluginmanager.*
+import net.pterodactylus.sone.freenet.plugin.*
 import net.pterodactylus.sone.test.*
 import org.hamcrest.MatcherAssert.*
 import org.hamcrest.Matchers.*
 import org.junit.*
+import org.junit.rules.*
+import org.mockito.*
 import org.mockito.Mockito.*
 
 /**
@@ -16,6 +19,10 @@ import org.mockito.Mockito.*
  */
 class FreenetModuleTest {
 
+       @Rule
+       @JvmField
+       val expectedException = ExpectedException.none()!!
+
        private val sessionManager = mock<SessionManager>()
        private val pluginRespirator = deepMock<PluginRespirator>().apply {
                whenever(getSessionManager("Sone")).thenReturn(sessionManager)
@@ -34,13 +41,9 @@ class FreenetModuleTest {
        }
 
        @Test
-       fun `plugin respirator is returned correctly`() {
-               assertThat(injector.getInstance(), sameInstance(pluginRespirator))
-       }
-
-       @Test
-       fun `plugin respirator is returned as singleton`() {
-               verifySingletonInstance<PluginRespirator>()
+       fun `plugin respirator is not bound`() {
+               expectedException.expect(Exception::class.java)
+               injector.getInstance<PluginRespirator>()
        }
 
        @Test
@@ -94,4 +97,16 @@ class FreenetModuleTest {
                verifySingletonInstance<PageMaker>()
        }
 
+       @Test
+       fun `plugin respirator facade is returned correctly`() {
+               val pluginRespiratorFacade = injector.getInstance<PluginRespiratorFacade>()
+               pluginRespiratorFacade.getPluginTalker(mock(), "test.plugin", "test-request-1")
+               verify(pluginRespirator).getPluginTalker(any(), ArgumentMatchers.eq("test.plugin"), ArgumentMatchers.eq("test-request-1"))
+       }
+
+       @Test
+       fun `plugin respirator facade is returned as singleton`() {
+               verifySingletonInstance<PluginRespiratorFacade>()
+       }
+
 }
index 31b232d..123269c 100644 (file)
@@ -10,6 +10,7 @@ import freenet.pluginmanager.*
 import net.pterodactylus.sone.core.*
 import net.pterodactylus.sone.database.*
 import net.pterodactylus.sone.database.memory.*
+import net.pterodactylus.sone.freenet.plugin.*
 import net.pterodactylus.sone.freenet.wot.*
 import net.pterodactylus.sone.test.*
 import net.pterodactylus.util.config.*
@@ -41,7 +42,7 @@ class SoneModuleTest {
                createInjector(
                                SoneModule(sonePlugin, EventBus()),
                                FreenetInterface::class.isProvidedByDeepMock(),
-                               PluginRespirator::class.isProvidedByDeepMock()
+                               PluginRespiratorFacade::class.isProvidedByDeepMock()
                )
        }
 
@@ -198,7 +199,7 @@ class SoneModuleTest {
                val injector = createInjector(
                                SoneModule(sonePlugin, eventBus),
                                FreenetInterface::class.isProvidedByDeepMock(),
-                               PluginRespirator::class.isProvidedByDeepMock()
+                               PluginRespiratorFacade::class.isProvidedByDeepMock()
                )
                val core = injector.getInstance<Core>()
                verify(eventBus).register(core)