From dcc7d35b09cc018d638292556a35257c44b86602 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 27 Oct 2019 17:18:32 +0100 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Make=20facade=20injectable=20inst?= =?utf8?q?ead=20of=20plugin=20respirator?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/main/FreenetModule.kt | 3 ++- .../pterodactylus/sone/main/FreenetModuleTest.kt | 29 ++++++++++++++++------ .../net/pterodactylus/sone/main/SoneModuleTest.kt | 5 ++-- 3 files changed, 27 insertions(+), 10 deletions(-) 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) -- 2.7.4