|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.core.env;
|
18 | 18 |
|
19 |
| -import java.util.Collections; |
20 | 19 | import java.util.Map;
|
21 | 20 |
|
22 | 21 | import org.junit.jupiter.api.Test;
|
|
27 | 26 | * Tests for {@link CompositePropertySource}.
|
28 | 27 | *
|
29 | 28 | * @author Phillip Webb
|
| 29 | + * @author Sam Brannen |
30 | 30 | */
|
31 | 31 | class CompositePropertySourceTests {
|
32 | 32 |
|
33 | 33 | @Test
|
34 | 34 | 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()); |
38 | 38 | CompositePropertySource composite = new CompositePropertySource("c");
|
39 | 39 | composite.addPropertySource(p2);
|
40 | 40 | composite.addPropertySource(p3);
|
41 | 41 | composite.addPropertySource(p1);
|
42 | 42 | 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'"); |
48 | 46 | }
|
49 | 47 |
|
50 | 48 | @Test
|
|
0 commit comments