From 32ca1db3e092387c59ef351cf5bd75dee0494ec9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 25 Jan 2017 18:40:20 +0100 Subject: [PATCH] Improve Guice provider methods --- src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt | 4 ++-- src/test/kotlin/net/pterodactylus/sone/test/Guice.kt | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt index e9137b0..9b591a0 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt @@ -20,8 +20,8 @@ import net.pterodactylus.sone.freenet.fcp.Command.AccessType 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 @@ -64,7 +64,7 @@ class FcpInterfaceTest { @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))) } diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt b/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt index f8feeef..5eca8fa 100644 --- a/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt +++ b/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt @@ -1,6 +1,10 @@ package net.pterodactylus.sone.test import com.google.inject.Module +import javax.inject.Provider import kotlin.reflect.KClass -fun T.bindAs(bindClass: KClass) = Module { it.bind(bindClass.java).toInstance(this@bindAs) } +fun KClass.isInstance(instance: T) = Module { it.bind(this.java).toInstance(instance) } +fun KClass.isProvidedBy(instance: T) = Module { it.bind(this.java).toProvider { instance } } +fun KClass.isProvidedBy(provider: com.google.inject.Provider) = Module { it.bind(this.java).toProvider(provider) } +fun KClass.isProvidedBy(provider: KClass>) = Module { it.bind(this.java).toProvider(provider.java) } -- 2.7.4