Skip to content

Commit

Permalink
test map multibinding elements overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
luozejiaqun committed Dec 20, 2024
1 parent ffbb603 commit b81de19
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.koin.core

import org.koin.Simple
import org.koin.core.parameter.parametersOf
import org.koin.core.qualifier.named
import org.koin.dsl.koinApplication
import org.koin.dsl.module
import kotlin.random.Random
import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertEquals
Expand Down Expand Up @@ -154,6 +152,40 @@ class MultibindingTest {
assertNull(scopeMap["invalid key"])
}

@Test
fun `override map multibinding elements that define in linked scope`() {
val rootComponent = Simple.Component1()
val scopeComponent = Simple.Component2()
val scopeId = "myScope"
val scopeKey = named("KEY")
val app = koinApplication {
modules(
module {
declareMapMultibinding<String, Simple.ComponentInterface1> {
intoMap(keyOfComponent1) { rootComponent }
}
scope(scopeKey) {
declareMapMultibinding<String, Simple.ComponentInterface1> {
intoMap(keyOfComponent1) { scopeComponent }
intoMap(keyOfComponent2) { Simple.Component2() }
}
}
},
)
}

val koin = app.koin
val myScope = koin.createScope(scopeId, scopeKey)
val rootMap: Map<String, Simple.ComponentInterface1> = koin.getMapMultibinding()
val scopeMap: Map<String, Simple.ComponentInterface1> = myScope.getMapMultibinding()
assertEquals(1, rootMap.size)
assertEquals(rootComponent, rootMap[keyOfComponent1])
assertTrue { rootMap.containsValue(rootComponent) }
assertEquals(2, scopeMap.size)
assertEquals(scopeComponent, scopeMap[keyOfComponent1])
assertTrue { scopeMap.containsValue(scopeComponent) }
}

@Test
fun `declare set multibinding in root scope`() {
val app = koinApplication {
Expand Down

0 comments on commit b81de19

Please sign in to comment.