Skip to content

Commit 3206ef0

Browse files
committed
Add additional test to cover provider bindings
1 parent 56dbee5 commit 3206ef0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

core/src/test/kotlin/org/jlleitschuh/guice/ModuleTest.kt

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ package org.jlleitschuh.guice
22

33
import com.google.inject.AbstractModule
44
import com.google.inject.Guice
5+
import org.junit.jupiter.api.Assertions.assertNotSame
56
import org.junit.jupiter.api.Assertions.assertSame
67
import org.junit.jupiter.api.Assertions.assertTrue
78
import org.junit.jupiter.api.Test
9+
import javax.inject.Provider
810

911
class ModuleTest {
1012
interface Interface
1113

1214
class Implementation : Interface
1315

16+
class InterfaceProvider : Provider<Interface> {
17+
override fun get() = Implementation()
18+
}
19+
1420
@Test
1521
fun `simple module`() {
1622
val simpleModule = module {
@@ -22,7 +28,7 @@ class ModuleTest {
2228
}
2329

2430
@Test
25-
fun `simple module reified`() {
31+
fun `simple module reified binding methods`() {
2632
val simpleModule = module {
2733
bind<Interface>().to<Implementation>()
2834
}
@@ -63,4 +69,15 @@ class ModuleTest {
6369
injector.getInstance(key<Interface>())
6470
}
6571

72+
@Test
73+
fun `module binding to provider using reified methods`() {
74+
val module = module {
75+
bind<Interface>().toProvider<InterfaceProvider>()
76+
}
77+
val injector = Guice.createInjector(module)
78+
79+
val first = injector.getInstance(key<Interface>())
80+
val second = injector.getInstance(key<Interface>())
81+
assertNotSame(first, second)
82+
}
6683
}

0 commit comments

Comments
 (0)