From: David ‘Bombe’ Roden Date: Sun, 27 Oct 2019 16:18:32 +0000 (+0100) Subject: 🚧 Make facade injectable instead of plugin respirator X-Git-Tag: v81^2~106 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=dcc7d35b09cc018d638292556a35257c44b86602;p=Sone.git 🚧 Make facade injectable instead of plugin respirator --- diff --git a/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt b/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt index 9b5fa2e..9fff176 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/FreenetModule.kt @@ -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 }) + bind(PluginRespiratorFacade::class.java).toProvider(Provider { FredPluginRespiratorFacade(pluginRespirator) }).`in`(Singleton::class.java) pluginRespirator.node!!.let { node -> bind(Node::class.java).toProvider(Provider { node }) } bind(HighLevelSimpleClient::class.java).toProvider(Provider { pluginRespirator.hlSimpleClient!! }) bind(ToadletContainer::class.java).toProvider(Provider { pluginRespirator.toadletContainer }) diff --git a/src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt index 2f55d52..32d2ca4 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/FreenetModuleTest.kt @@ -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() private val pluginRespirator = deepMock().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() + fun `plugin respirator is not bound`() { + expectedException.expect(Exception::class.java) + injector.getInstance() } @Test @@ -94,4 +97,16 @@ class FreenetModuleTest { verifySingletonInstance() } + @Test + fun `plugin respirator facade is returned correctly`() { + val pluginRespiratorFacade = injector.getInstance() + 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() + } + } diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt index 31b232d..123269c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt @@ -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() verify(eventBus).register(core)