Skip to content

Commit d189e16

Browse files
committed
Polish CompositePropertySource[Tests]
1 parent 7c508a4 commit d189e16

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.springframework.core.env;
1818

1919
import java.util.ArrayList;
20-
import java.util.Arrays;
2120
import java.util.Collection;
21+
import java.util.Collections;
2222
import java.util.LinkedHashSet;
2323
import java.util.List;
2424
import java.util.Set;
@@ -90,7 +90,7 @@ public String[] getPropertyNames() {
9090
total += names.length;
9191
}
9292
Set<String> allNames = new LinkedHashSet<>(total);
93-
namesList.forEach(names -> allNames.addAll(Arrays.asList(names)));
93+
namesList.forEach(names -> Collections.addAll(allNames, names));
9494
return StringUtils.toStringArray(allNames);
9595
}
9696

spring-core/src/test/java/org/springframework/core/env/CompositePropertySourceTests.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.core.env;
1818

19-
import java.util.Collections;
2019
import java.util.Map;
2120

2221
import org.junit.jupiter.api.Test;
@@ -27,24 +26,23 @@
2726
* Tests for {@link CompositePropertySource}.
2827
*
2928
* @author Phillip Webb
29+
* @author Sam Brannen
3030
*/
3131
class CompositePropertySourceTests {
3232

3333
@Test
3434
void addFirst() {
35-
PropertySource<?> p1 = new MapPropertySource("p1", Collections.emptyMap());
36-
PropertySource<?> p2 = new MapPropertySource("p2", Collections.emptyMap());
37-
PropertySource<?> p3 = new MapPropertySource("p3", Collections.emptyMap());
35+
PropertySource<?> p1 = new MapPropertySource("p1", Map.of());
36+
PropertySource<?> p2 = new MapPropertySource("p2", Map.of());
37+
PropertySource<?> p3 = new MapPropertySource("p3", Map.of());
3838
CompositePropertySource composite = new CompositePropertySource("c");
3939
composite.addPropertySource(p2);
4040
composite.addPropertySource(p3);
4141
composite.addPropertySource(p1);
4242
composite.addFirstPropertySource(p1);
43-
String s = composite.toString();
44-
int i1 = s.indexOf("name='p1'");
45-
int i2 = s.indexOf("name='p2'");
46-
int i3 = s.indexOf("name='p3'");
47-
assertThat(((i1 < i2) && (i2 < i3))).as("Bad order: " + s).isTrue();
43+
44+
assertThat(composite.getPropertySources()).extracting(PropertySource::getName).containsExactly("p1", "p2", "p3");
45+
assertThat(composite).asString().containsSubsequence("name='p1'", "name='p2'", "name='p3'");
4846
}
4947

5048
@Test

0 commit comments

Comments
 (0)