Skip to content

Commit 40b3372

Browse files
committed
Polish
1 parent bfae0d7 commit 40b3372

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,14 @@ protected Yaml createYaml() {
7676

7777
public Map<String, Object> load() {
7878
final Map<String, Object> result = new LinkedHashMap<String, Object>();
79-
process(new MatchCallback() {
80-
81-
@Override
82-
public void process(Properties properties, Map<String, Object> map) {
83-
result.putAll(getFlattenedMap(map));
84-
}
85-
79+
process((properties, map) -> {
80+
result.putAll(getFlattenedMap(map));
8681
});
8782
return result;
8883
}
8984

9085
/**
91-
* {@link Constructor}.
86+
* {@link Constructor} that tracks property origins.
9287
*/
9388
private class OriginTrackingConstructor extends StrictMapAppenderConstructor {
9489

@@ -100,14 +95,16 @@ protected Object constructObject(Node node) {
10095
}
10196
}
10297
else if (node instanceof MappingNode) {
103-
List<NodeTuple> value = ((MappingNode) node).getValue();
104-
List<NodeTuple> updatedValues = value.stream().map(nt -> new NodeTuple(KeyScalarNode.get(nt.getKeyNode()),
105-
nt.getValueNode())).collect(Collectors.toList());
106-
((MappingNode) node).setValue(updatedValues);
98+
replaceMappingNodeKeys((MappingNode) node);
10799
}
108100
return super.constructObject(node);
109101
}
110102

103+
private void replaceMappingNodeKeys(MappingNode node) {
104+
node.setValue(node.getValue().stream().map(KeyScalarNode::get)
105+
.collect(Collectors.toList()));
106+
}
107+
111108
private Object constructTrackedObject(Node node, Object value) {
112109
PropertyOrigin origin = getOrigin(node);
113110
return OriginTrackedValue.of(value, origin);
@@ -128,7 +125,14 @@ private PropertyOrigin getOrigin(Node node) {
128125
private static class KeyScalarNode extends ScalarNode {
129126

130127
KeyScalarNode(ScalarNode node) {
131-
super(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(), node.getStyle());
128+
super(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(),
129+
node.getStyle());
130+
}
131+
132+
public static NodeTuple get(NodeTuple nodeTuple) {
133+
Node keyNode = nodeTuple.getKeyNode();
134+
Node valueNode = nodeTuple.getValueNode();
135+
return new NodeTuple(KeyScalarNode.get(keyNode), valueNode);
132136
}
133137

134138
private static Node get(Node node) {
@@ -155,6 +159,10 @@ public void addImplicitResolver(Tag tag, Pattern regexp, String first) {
155159

156160
}
157161

162+
/**
163+
* {@link SpringProfileDocumentMatcher} that deals with {@link OriginTrackedValue
164+
* OriginTrackedValues}.
165+
*/
158166
private static class OriginTrackedSpringProfileDocumentMatcher
159167
extends SpringProfileDocumentMatcher {
160168

spring-boot/src/test/java/org/springframework/boot/web/servlet/context/AnnotationConfigServletWebServerApplicationContextTests.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import org.springframework.beans.factory.annotation.Autowired;
3131
import org.springframework.boot.testutil.MockServlet;
32-
import org.springframework.boot.web.servlet.context.config.ExampleEmbeddedWebApplicationConfiguration;
32+
import org.springframework.boot.web.servlet.context.config.ExampleServletWebServerApplicationConfiguration;
3333
import org.springframework.boot.web.servlet.server.MockServletWebServerFactory;
3434
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
3535
import org.springframework.context.annotation.Bean;
@@ -55,22 +55,23 @@ public class AnnotationConfigServletWebServerApplicationContextTests {
5555
@Test
5656
public void createFromScan() throws Exception {
5757
this.context = new AnnotationConfigServletWebServerApplicationContext(
58-
ExampleEmbeddedWebApplicationConfiguration.class.getPackage().getName());
58+
ExampleServletWebServerApplicationConfiguration.class.getPackage()
59+
.getName());
5960
verifyContext();
6061
}
6162

6263
@Test
6364
public void sessionScopeAvailable() throws Exception {
6465
this.context = new AnnotationConfigServletWebServerApplicationContext(
65-
ExampleEmbeddedWebApplicationConfiguration.class,
66+
ExampleServletWebServerApplicationConfiguration.class,
6667
SessionScopedComponent.class);
6768
verifyContext();
6869
}
6970

7071
@Test
7172
public void sessionScopeAvailableToServlet() throws Exception {
7273
this.context = new AnnotationConfigServletWebServerApplicationContext(
73-
ExampleEmbeddedWebApplicationConfiguration.class,
74+
ExampleServletWebServerApplicationConfiguration.class,
7475
ExampleServletWithAutowired.class, SessionScopedComponent.class);
7576
Servlet servlet = this.context.getBean(ExampleServletWithAutowired.class);
7677
assertThat(servlet).isNotNull();
@@ -79,23 +80,23 @@ public void sessionScopeAvailableToServlet() throws Exception {
7980
@Test
8081
public void createFromConfigClass() throws Exception {
8182
this.context = new AnnotationConfigServletWebServerApplicationContext(
82-
ExampleEmbeddedWebApplicationConfiguration.class);
83+
ExampleServletWebServerApplicationConfiguration.class);
8384
verifyContext();
8485
}
8586

8687
@Test
8788
public void registerAndRefresh() throws Exception {
8889
this.context = new AnnotationConfigServletWebServerApplicationContext();
89-
this.context.register(ExampleEmbeddedWebApplicationConfiguration.class);
90+
this.context.register(ExampleServletWebServerApplicationConfiguration.class);
9091
this.context.refresh();
9192
verifyContext();
9293
}
9394

9495
@Test
9596
public void scanAndRefresh() throws Exception {
9697
this.context = new AnnotationConfigServletWebServerApplicationContext();
97-
this.context.scan(
98-
ExampleEmbeddedWebApplicationConfiguration.class.getPackage().getName());
98+
this.context.scan(ExampleServletWebServerApplicationConfiguration.class
99+
.getPackage().getName());
99100
this.context.refresh();
100101
verifyContext();
101102
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Phillip Webb
3232
*/
3333
@Configuration
34-
public class ExampleEmbeddedWebApplicationConfiguration {
34+
public class ExampleServletWebServerApplicationConfiguration {
3535

3636
@Bean
3737
public MockServletWebServerFactory webServerFactory() {

0 commit comments

Comments
 (0)