From b81de19f08b393e732e5983909bf87338a948006 Mon Sep 17 00:00:00 2001 From: jinzequn Date: Fri, 20 Dec 2024 13:43:33 +0800 Subject: [PATCH] test map multibinding elements overriding --- .../kotlin/org/koin/core/MultibindingTest.kt | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/projects/core/koin-core/src/commonTest/kotlin/org/koin/core/MultibindingTest.kt b/projects/core/koin-core/src/commonTest/kotlin/org/koin/core/MultibindingTest.kt index 41b3462e3..822577ac0 100644 --- a/projects/core/koin-core/src/commonTest/kotlin/org/koin/core/MultibindingTest.kt +++ b/projects/core/koin-core/src/commonTest/kotlin/org/koin/core/MultibindingTest.kt @@ -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 @@ -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 { + intoMap(keyOfComponent1) { rootComponent } + } + scope(scopeKey) { + declareMapMultibinding { + intoMap(keyOfComponent1) { scopeComponent } + intoMap(keyOfComponent2) { Simple.Component2() } + } + } + }, + ) + } + + val koin = app.koin + val myScope = koin.createScope(scopeId, scopeKey) + val rootMap: Map = koin.getMapMultibinding() + val scopeMap: Map = 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 {