|
8 | 8 | import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME; |
9 | 9 | import static java.nio.charset.StandardCharsets.UTF_8; |
10 | 10 | import static java.util.Collections.singletonMap; |
| 11 | +import static java.util.Objects.requireNonNull; |
11 | 12 | import static org.assertj.core.api.Assertions.assertThat; |
12 | 13 | import static org.mockito.Mockito.lenient; |
13 | 14 | import static org.mockito.Mockito.when; |
|
18 | 19 | import java.io.IOException; |
19 | 20 | import java.io.InputStream; |
20 | 21 | import java.io.OutputStream; |
21 | | -import java.net.URL; |
22 | 22 | import java.nio.file.Files; |
23 | 23 | import java.nio.file.Path; |
24 | 24 | import java.nio.file.Paths; |
@@ -132,12 +132,12 @@ void classpathApplicationYamlContainingMultipleYamlDefinitions(String fileName) |
132 | 132 |
|
133 | 133 | @ParameterizedTest |
134 | 134 | @ValueSource(strings = {"application.yaml", APPLICATION_YML}) |
135 | | - void yamlFileInCurrentDir(String fileName) throws Exception { |
| 135 | + void yamlFileInCurrentDir(String fileName) throws IOException { |
136 | 136 | Path yamlPath = Paths.get(fileName); |
137 | 137 | try { |
138 | | - URL url = getClass().getClassLoader().getResource(APPLICATION_YML); |
139 | | - String content = readString(Paths.get(url.toURI())); |
140 | | - writeString(yamlPath, content); |
| 138 | + try (InputStream in = requireNonNull(openClasspathResource(APPLICATION_YML))) { |
| 139 | + Files.copy(in, yamlPath); |
| 140 | + } |
141 | 141 | when(system.openFile(fileName)).thenCallRealMethod(); |
142 | 142 | SpringBootServiceNameDetector guesser = new SpringBootServiceNameDetector(system); |
143 | 143 | Resource result = guesser.createResource(config); |
@@ -165,10 +165,11 @@ void getFromCommandlineArgsWithProcessHandle() throws ReflectiveOperationExcepti |
165 | 165 | @Test |
166 | 166 | void getFromCommandlineArgsWithSystemProperty() { |
167 | 167 | when(system.getProperty("sun.java.command")) |
168 | | - .thenReturn("/bin/java sweet-spring.jar --spring.application.name=bullpen --quiet=never"); |
| 168 | + .thenReturn( |
| 169 | + "/bin/java sweet-spring.jar --spring.application.name=bullpen-v2 --quiet=never"); |
169 | 170 | SpringBootServiceNameDetector guesser = new SpringBootServiceNameDetector(system); |
170 | 171 | Resource result = guesser.createResource(config); |
171 | | - expectServiceName(result, "bullpen"); |
| 172 | + expectServiceName(result, "bullpen-v2"); |
172 | 173 | } |
173 | 174 |
|
174 | 175 | @Test |
@@ -210,11 +211,6 @@ private static void writeString(Path path, String value) throws IOException { |
210 | 211 | } |
211 | 212 | } |
212 | 213 |
|
213 | | - private static String readString(Path path) throws Exception { |
214 | | - byte[] allBytes = Files.readAllBytes(path); |
215 | | - return new String(allBytes, UTF_8); |
216 | | - } |
217 | | - |
218 | 214 | private InputStream openClasspathResource(String resource) { |
219 | 215 | return getClass().getClassLoader().getResourceAsStream(resource); |
220 | 216 | } |
|
0 commit comments