-
-
Notifications
You must be signed in to change notification settings - Fork 691
/
ModuleDeclarationRulesTest.kt
75 lines (67 loc) · 2.13 KB
/
ModuleDeclarationRulesTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.koin.dsl
import kotlin.test.assertEquals
import kotlin.test.fail
import kotlin.test.Test
import org.koin.Simple
import org.koin.core.error.DefinitionOverrideException
import org.koin.core.logger.Level
import org.koin.core.qualifier.named
import org.koin.test.assertDefinitionsCount
class ModuleDeclarationRulesTest {
@Test
fun `don't allow redeclaration`() {
koinApplication {
modules(module {
single { Simple.ComponentA() }
single { Simple.ComponentA() }
})
}
}
@Test
fun `allow redeclaration - different names`() {
val app = koinApplication {
printLogger(Level.INFO)
modules(module {
single(named("default")) { Simple.ComponentA() }
single(named("other")) { Simple.ComponentA() }
})
}
app.assertDefinitionsCount(2)
}
@Test
fun `allow qualifier redeclaration - same names`() {
val koin = koinApplication {
modules(module {
single(named("default")) { Simple.ComponentA() }
single(named("default")) { Simple.ComponentB(get(named("default"))) }
})
}.koin
val a = koin.get<Simple.ComponentA>(named("default"))
val b = koin.get<Simple.ComponentB>(named("default"))
assertEquals(a, b.a)
}
@Test
fun `allow redeclaration - default`() {
val app = koinApplication {
modules(module {
single { Simple.ComponentA() }
single(named("other")) { Simple.ComponentA() }
})
}
app.assertDefinitionsCount(2)
}
@Test
fun `don't allow redeclaration with different implementation`() {
try {
koinApplication {
modules(
module {
single<Simple.ComponentInterface1> { Simple.Component1() }
single<Simple.ComponentInterface1> { Simple.Component2() }
})
}
} catch (e: DefinitionOverrideException) {
e.printStackTrace()
}
}
}