|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,6 +16,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.beans.factory.support; |
|
|
|
package org.springframework.beans.factory.support; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.AbstractMap.SimpleEntry; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
@ -34,11 +35,9 @@ public class ManagedMapTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void mergeSunnyDay() { |
|
|
|
public void mergeSunnyDay() { |
|
|
|
ManagedMap parent = new ManagedMap(); |
|
|
|
ManagedMap parent = ManagedMap.ofEntries(new SimpleEntry<>("one", "one"), |
|
|
|
parent.put("one", "one"); |
|
|
|
new SimpleEntry<>("two", "two")); |
|
|
|
parent.put("two", "two"); |
|
|
|
ManagedMap child = ManagedMap.ofEntries(new SimpleEntry<>("tree", "three")); |
|
|
|
ManagedMap child = new ManagedMap(); |
|
|
|
|
|
|
|
child.put("three", "three"); |
|
|
|
|
|
|
|
child.setMergeEnabled(true); |
|
|
|
child.setMergeEnabled(true); |
|
|
|
Map mergedMap = (Map) child.merge(parent); |
|
|
|
Map mergedMap = (Map) child.merge(parent); |
|
|
|
assertThat(mergedMap.size()).as("merge() obviously did not work.").isEqualTo(3); |
|
|
|
assertThat(mergedMap.size()).as("merge() obviously did not work.").isEqualTo(3); |
|
|
|
@ -67,9 +66,8 @@ public class ManagedMapTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void mergeEmptyChild() { |
|
|
|
public void mergeEmptyChild() { |
|
|
|
ManagedMap parent = new ManagedMap(); |
|
|
|
ManagedMap parent = ManagedMap.ofEntries(new SimpleEntry<>("one", "one"), |
|
|
|
parent.put("one", "one"); |
|
|
|
new SimpleEntry<>("two", "two")); |
|
|
|
parent.put("two", "two"); |
|
|
|
|
|
|
|
ManagedMap child = new ManagedMap(); |
|
|
|
ManagedMap child = new ManagedMap(); |
|
|
|
child.setMergeEnabled(true); |
|
|
|
child.setMergeEnabled(true); |
|
|
|
Map mergedMap = (Map) child.merge(parent); |
|
|
|
Map mergedMap = (Map) child.merge(parent); |
|
|
|
@ -78,11 +76,9 @@ public class ManagedMapTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void mergeChildValuesOverrideTheParents() { |
|
|
|
public void mergeChildValuesOverrideTheParents() { |
|
|
|
ManagedMap parent = new ManagedMap(); |
|
|
|
ManagedMap parent = ManagedMap.ofEntries(new SimpleEntry<>("one", "one"), |
|
|
|
parent.put("one", "one"); |
|
|
|
new SimpleEntry<>("two", "two")); |
|
|
|
parent.put("two", "two"); |
|
|
|
ManagedMap child = ManagedMap.ofEntries(new SimpleEntry<>("one", "fork")); |
|
|
|
ManagedMap child = new ManagedMap(); |
|
|
|
|
|
|
|
child.put("one", "fork"); |
|
|
|
|
|
|
|
child.setMergeEnabled(true); |
|
|
|
child.setMergeEnabled(true); |
|
|
|
Map mergedMap = (Map) child.merge(parent); |
|
|
|
Map mergedMap = (Map) child.merge(parent); |
|
|
|
// child value for 'one' must override parent value...
|
|
|
|
// child value for 'one' must override parent value...
|
|
|
|
|