package net.pterodactylus.sone.test import com.google.inject.Injector import com.google.inject.Module import javax.inject.Provider import kotlin.reflect.KClass 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) } inline fun KClass.isProvidedByMock() = Module { it.bind(this.java).toProvider { mock() } } inline fun Injector.getInstance() = getInstance(T::class.java)!! fun supply(javaClass: Class): Source = object : Source { override fun fromInstance(instance: T) = Module { it.bind(javaClass).toInstance(instance) } override fun byInstance(instance: T) = Module { it.bind(javaClass).toProvider { instance } } override fun byProvider(provider: com.google.inject.Provider) = Module { it.bind(javaClass).toProvider(provider) } override fun byProvider(provider: Class>) = Module { it.bind(javaClass).toProvider(provider) } } interface Source { fun fromInstance(instance: T): Module fun byInstance(instance: T): Module fun byProvider(provider: com.google.inject.Provider): Module fun byProvider(provider: Class>): Module }