@@ -2,15 +2,21 @@ package org.jlleitschuh.guice
2
2
3
3
import com.google.inject.AbstractModule
4
4
import com.google.inject.Guice
5
+ import org.junit.jupiter.api.Assertions.assertNotSame
5
6
import org.junit.jupiter.api.Assertions.assertSame
6
7
import org.junit.jupiter.api.Assertions.assertTrue
7
8
import org.junit.jupiter.api.Test
9
+ import javax.inject.Provider
8
10
9
11
class ModuleTest {
10
12
interface Interface
11
13
12
14
class Implementation : Interface
13
15
16
+ class InterfaceProvider : Provider <Interface > {
17
+ override fun get () = Implementation ()
18
+ }
19
+
14
20
@Test
15
21
fun `simple module` () {
16
22
val simpleModule = module {
@@ -22,7 +28,7 @@ class ModuleTest {
22
28
}
23
29
24
30
@Test
25
- fun `simple module reified` () {
31
+ fun `simple module reified binding methods ` () {
26
32
val simpleModule = module {
27
33
bind<Interface >().to<Implementation >()
28
34
}
@@ -63,4 +69,15 @@ class ModuleTest {
63
69
injector.getInstance(key<Interface >())
64
70
}
65
71
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
+ }
66
83
}
0 commit comments