|
10 | 10 |
|
11 | 11 | package org.junit.platform.launcher.core;
|
12 | 12 |
|
| 13 | +import static org.assertj.core.api.Assertions.as; |
13 | 14 | import static org.assertj.core.api.Assertions.assertThat;
|
14 | 15 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
15 | 16 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
18 | 19 | import java.net.URLClassLoader;
|
19 | 20 | import java.nio.file.Files;
|
20 | 21 | import java.nio.file.Path;
|
21 |
| -import java.util.List; |
22 | 22 | import java.util.Map;
|
23 | 23 | import java.util.Properties;
|
24 | 24 | import java.util.logging.Level;
|
25 | 25 | import java.util.logging.LogRecord;
|
26 | 26 |
|
| 27 | +import org.assertj.core.api.InstanceOfAssertFactories; |
27 | 28 | import org.junit.jupiter.api.AfterEach;
|
28 | 29 | import org.junit.jupiter.api.BeforeEach;
|
29 | 30 | import org.junit.jupiter.api.Test;
|
@@ -204,31 +205,32 @@ void ignoresSystemPropertyAndConfigFileWhenImplicitLookupsAreDisabled() {
|
204 | 205 | @Test
|
205 | 206 | void warnsOnMultiplePropertyResources(@TempDir Path tempDir, @TrackLogRecords LogRecordListener logRecordListener)
|
206 | 207 | throws Exception {
|
| 208 | + |
207 | 209 | Properties properties = new Properties();
|
208 | 210 | properties.setProperty(KEY, "from second config file");
|
209 | 211 | try (var out = Files.newOutputStream(tempDir.resolve(CONFIG_FILE_NAME))) {
|
210 | 212 | properties.store(out, "");
|
211 | 213 | }
|
| 214 | + |
212 | 215 | ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
|
| 216 | + URL originalResource = originalClassLoader.getResource(CONFIG_FILE_NAME); |
| 217 | + |
213 | 218 | try (var customClassLoader = new URLClassLoader(new URL[] { tempDir.toUri().toURL() }, originalClassLoader)) {
|
214 | 219 | Thread.currentThread().setContextClassLoader(customClassLoader);
|
215 | 220 | ConfigurationParameters configParams = fromMapAndFile(Map.of(), CONFIG_FILE_NAME);
|
216 | 221 |
|
217 | 222 | assertThat(configParams.get(KEY)).contains(CONFIG_FILE);
|
218 | 223 |
|
219 |
| - List<String> loggedWarnings = logRecordListener.stream(Level.WARNING) // |
220 |
| - .map(LogRecord::getMessage) // |
221 |
| - .toList(); |
222 |
| - assertThat(loggedWarnings) // |
223 |
| - .hasSize(1); |
224 |
| - assertThat(loggedWarnings.getFirst()) // |
225 |
| - .contains("Discovered 2 '" + CONFIG_FILE_NAME |
226 |
| - + "' configuration files on the classpath (see below); only the first (*) will be used.") // |
227 |
| - .contains("- " |
228 |
| - + Path.of( |
229 |
| - "build/resources/test/test-junit-platform.properties").toAbsolutePath().toUri().toURL() |
230 |
| - + " (*)") // |
231 |
| - .contains("- " + tempDir.resolve(CONFIG_FILE_NAME).toUri().toURL()); |
| 224 | + assertThat(logRecordListener.stream(Level.WARNING).map(LogRecord::getMessage)) // |
| 225 | + .hasSize(1) // |
| 226 | + .first(as(InstanceOfAssertFactories.STRING)) // |
| 227 | + .contains(""" |
| 228 | + Discovered 2 '%s' configuration files on the classpath (see below); \ |
| 229 | + only the first (*) will be used. |
| 230 | + - %s (*) |
| 231 | + - %s"""// |
| 232 | + .formatted(CONFIG_FILE_NAME, originalResource, |
| 233 | + tempDir.resolve(CONFIG_FILE_NAME).toUri().toURL())); |
232 | 234 | }
|
233 | 235 | finally {
|
234 | 236 | Thread.currentThread().setContextClassLoader(originalClassLoader);
|
|
0 commit comments