|
16 | 16 |
|
17 | 17 | package org.springframework.context.support;
|
18 | 18 |
|
| 19 | +import java.nio.file.InvalidPathException; |
| 20 | + |
19 | 21 | import org.junit.jupiter.api.AfterEach;
|
20 | 22 | import org.junit.jupiter.api.Test;
|
| 23 | +import org.junit.jupiter.api.condition.OS; |
21 | 24 |
|
22 | 25 | import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
23 | 26 | import org.springframework.beans.factory.config.BeanDefinition;
|
@@ -238,25 +241,36 @@ private void assertGetResourceSemantics(ResourceLoader resourceLoader, Class<? e
|
238 | 241 | }
|
239 | 242 |
|
240 | 243 | String relativePathLocation = "foo";
|
241 |
| - String pingLocation = "ping:foo"; |
242 | 244 | String fileLocation = "file:foo";
|
| 245 | + String pingLocation = "ping:foo"; |
243 | 246 |
|
244 | 247 | Resource resource = context.getResource(relativePathLocation);
|
245 | 248 | assertThat(resource).isInstanceOf(defaultResourceType);
|
246 | 249 | resource = context.getResource(fileLocation);
|
247 | 250 | assertThat(resource).isInstanceOf(FileUrlResource.class);
|
248 | 251 |
|
249 |
| - context.addProtocolResolver(new PingPongProtocolResolver()); |
| 252 | + if (OS.WINDOWS.isCurrentOs()) { |
| 253 | + // On Windows we expect an error similar to the following. |
| 254 | + // java.nio.file.InvalidPathException: Illegal char <:> at index 4: ping:foo |
| 255 | + assertThatExceptionOfType(InvalidPathException.class) |
| 256 | + .isThrownBy(() -> context.getResource(pingLocation)) |
| 257 | + .withMessageContaining(pingLocation); |
| 258 | + } |
| 259 | + else { |
| 260 | + resource = context.getResource(pingLocation); |
| 261 | + assertThat(resource).isInstanceOf(defaultResourceType); |
| 262 | + } |
250 | 263 |
|
251 |
| - resource = context.getResource(pingLocation); |
252 |
| - assertThat(resource).asInstanceOf(type(ByteArrayResource.class)) |
253 |
| - .extracting(bar -> new String(bar.getByteArray(), UTF_8)) |
254 |
| - .isEqualTo("pong:foo"); |
| 264 | + context.addProtocolResolver(new PingPongProtocolResolver()); |
255 | 265 |
|
256 | 266 | resource = context.getResource(relativePathLocation);
|
257 | 267 | assertThat(resource).isInstanceOf(defaultResourceType);
|
258 | 268 | resource = context.getResource(fileLocation);
|
259 | 269 | assertThat(resource).isInstanceOf(FileUrlResource.class);
|
| 270 | + resource = context.getResource(pingLocation); |
| 271 | + assertThat(resource).asInstanceOf(type(ByteArrayResource.class)) |
| 272 | + .extracting(bar -> new String(bar.getByteArray(), UTF_8)) |
| 273 | + .isEqualTo("pong:foo"); |
260 | 274 | }
|
261 | 275 |
|
262 | 276 |
|
|
0 commit comments