projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
🚚 Move verification method to Guice helpers
[Sone.git]
/
src
/
test
/
kotlin
/
net
/
pterodactylus
/
sone
/
test
/
Guice.kt
diff --git
a/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt
b/src/test/kotlin/net/pterodactylus/sone/test/Guice.kt
index
c8f2417
..
a4ae1d5
100644
(file)
--- a/
src/test/kotlin/net/pterodactylus/sone/test/Guice.kt
+++ b/
src/test/kotlin/net/pterodactylus/sone/test/Guice.kt
@@
-2,6
+2,8
@@
package net.pterodactylus.sone.test
import com.google.inject.*
import com.google.inject.name.*
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.*
import org.mockito.*
import javax.inject.Provider
import kotlin.reflect.*
@@
-17,6
+19,13
@@
inline fun <reified T : Any> Injector.getInstance(annotation: Annotation? = null
?.let { getInstance(Key.get(object : TypeLiteral<T>() {}, it)) }
?: getInstance(Key.get(object : TypeLiteral<T>() {}))
?.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 }) }
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 }) }