private val module = FreenetModule(pluginRespirator)
private val injector = Guice.createInjector(module)
- private inline fun <reified T : Any> verifySingletonInstance() {
- val firstInstance = injector.getInstance<T>()
- val secondInstance = injector.getInstance<T>()
- assertThat(firstInstance, sameInstance(secondInstance))
- }
-
@Test
fun `plugin respirator is not bound`() {
expectedException.expect(Exception::class.java)
@Test
fun `node is returned as singleton`() {
- verifySingletonInstance<Node>()
+ injector.verifySingletonInstance<Node>()
}
@Test
@Test
fun `high level simply client is returned as singleton`() {
- verifySingletonInstance<HighLevelSimpleClient>()
+ injector.verifySingletonInstance<HighLevelSimpleClient>()
}
@Test
@Test
fun `session manager is returned as singleton`() {
- verifySingletonInstance<SessionManager>()
+ injector.verifySingletonInstance<SessionManager>()
verify(pluginRespirator).getSessionManager("Sone")
}
@Test
fun `toadlet container is returned as singleten`() {
- verifySingletonInstance<ToadletContainer>()
+ injector.verifySingletonInstance<ToadletContainer>()
}
@Test
@Test
fun `page maker is returned as singleton`() {
- verifySingletonInstance<PageMaker>()
+ injector.verifySingletonInstance<PageMaker>()
}
@Test
@Test
fun `plugin respirator facade is returned as singleton`() {
- verifySingletonInstance<PluginRespiratorFacade>()
+ injector.verifySingletonInstance<PluginRespiratorFacade>()
}
@Test
@Test
fun `plugin connector facade is returned as singleton`() {
- verifySingletonInstance<PluginConnector>()
+ injector.verifySingletonInstance<PluginConnector>()
}
}
import com.google.inject.*
import com.google.inject.name.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
import org.mockito.*
import javax.inject.Provider
import kotlin.reflect.*
?.let { getInstance(Key.get(object : TypeLiteral<T>() {}, it)) }
?: getInstance(Key.get(object : TypeLiteral<T>() {}))
+
+inline fun <reified T : Any> Injector.verifySingletonInstance() {
+ val firstInstance = getInstance<T>()
+ val secondInstance = getInstance<T>()
+ assertThat(firstInstance, sameInstance(secondInstance))
+}
+
fun <T : Any> supply(javaClass: Class<T>): Source<T> = object : Source<T> {
override fun fromInstance(instance: T) = Module { it.bind(javaClass).toInstance(instance) }
override fun byInstance(instance: T) = Module { it.bind(javaClass).toProvider(Provider<T> { instance }) }
@Test
fun `template context factory is created as singleton`() {
- val factory1 = injector.getInstance<TemplateContextFactory>()
- val factory2 = injector.getInstance<TemplateContextFactory>()
- assertThat(factory1, sameInstance(factory2))
+ injector.verifySingletonInstance<TemplateContextFactory>()
}
@Test
@Test
fun `notification manager is created as singleton`() {
- val firstNotificationManager = injector.getInstance<NotificationManager>()
- val secondNotificationManager = injector.getInstance<NotificationManager>()
- assertThat(firstNotificationManager, sameInstance(secondNotificationManager))
+ injector.verifySingletonInstance<NotificationManager>()
}
@Test
@Test
fun `notification handler is created as singleton`() {
- val firstNotificationHandler = injector.getInstance<NotificationHandler>()
- val secondNotificationHandler = injector.getInstance<NotificationHandler>()
- assertThat(firstNotificationHandler, sameInstance(secondNotificationHandler))
+ injector.verifySingletonInstance<NotificationHandler>()
}
}