import net.pterodactylus.sone.freenet.fcp.Command.AccessType.FULL_FCP
import net.pterodactylus.sone.freenet.fcp.Command.AccessType.RESTRICTED_FCP
import net.pterodactylus.sone.freenet.fcp.Command.Response
-import net.pterodactylus.sone.test.bindAs
import net.pterodactylus.sone.test.capture
+import net.pterodactylus.sone.test.isProvidedBy
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
import org.hamcrest.MatcherAssert.assertThat
@Test
fun `fcp interface is instantiated as singleton`() {
- val injector = Guice.createInjector(core.bindAs(Core::class))
+ val injector = Guice.createInjector(Core::class.isProvidedBy(core))
assertThat(injector.getInstance(FcpInterface::class.java), sameInstance(injector.getInstance(FcpInterface::class.java)))
}
package net.pterodactylus.sone.test
import com.google.inject.Module
+import javax.inject.Provider
import kotlin.reflect.KClass
-fun <T : Any> T.bindAs(bindClass: KClass<T>) = Module { it.bind(bindClass.java).toInstance(this@bindAs) }
+fun <T : Any> KClass<T>.isInstance(instance: T) = Module { it.bind(this.java).toInstance(instance) }
+fun <T : Any> KClass<T>.isProvidedBy(instance: T) = Module { it.bind(this.java).toProvider { instance } }
+fun <T : Any> KClass<T>.isProvidedBy(provider: com.google.inject.Provider<T>) = Module { it.bind(this.java).toProvider(provider) }
+fun <T : Any> KClass<T>.isProvidedBy(provider: KClass<out Provider<T>>) = Module { it.bind(this.java).toProvider(provider.java) }