import freenet.clients.http.*
import freenet.node.*
import freenet.pluginmanager.*
+import net.pterodactylus.sone.freenet.plugin.*
import javax.inject.Provider
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 })
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.*
/**
*/
class FreenetModuleTest {
+ @Rule
+ @JvmField
+ val expectedException = ExpectedException.none()!!
+
private val sessionManager = mock<SessionManager>()
private val pluginRespirator = deepMock<PluginRespirator>().apply {
whenever(getSessionManager("Sone")).thenReturn(sessionManager)
}
@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
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>()
+ }
+
}
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.*
createInjector(
SoneModule(sonePlugin, EventBus()),
FreenetInterface::class.isProvidedByDeepMock(),
- PluginRespirator::class.isProvidedByDeepMock()
+ PluginRespiratorFacade::class.isProvidedByDeepMock()
)
}
val injector = createInjector(
SoneModule(sonePlugin, eventBus),
FreenetInterface::class.isProvidedByDeepMock(),
- PluginRespirator::class.isProvidedByDeepMock()
+ PluginRespiratorFacade::class.isProvidedByDeepMock()
)
val core = injector.getInstance<Core>()
verify(eventBus).register(core)