From d1d6eb095e5af75ac80bd5050bf2c50f9ce97077 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 3 Jul 2022 17:59:33 +0200 Subject: [PATCH] Fix GenericApplicationContextTests on Microsoft Windows (round 2) The previous change to the tests resulted in a failure on Windows when using the DefaultResourceLoader by expecting an exception when no exception is thrown. This commit narrows the scope of the if-clause to expect an exception only when using the FileSystemResourceLoader on Windows. See gh-28703, gh-28746 --- .../support/GenericApplicationContextTests.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java b/spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java index fcf467a906..acc1894d32 100644 --- a/spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/GenericApplicationContextTests.java @@ -249,9 +249,13 @@ class GenericApplicationContextTests { resource = context.getResource(fileLocation); assertThat(resource).isInstanceOf(FileUrlResource.class); - if (OS.WINDOWS.isCurrentOs()) { - // On Windows we expect an error similar to the following. - // java.nio.file.InvalidPathException: Illegal char <:> at index 4: ping:foo + // If we are using a FileSystemResourceLoader on Windows, we expect an error + // similar to the following since "ping:foo" is not a valid file name in the + // Windows file system and since the PingPongProtocolResolver has not yet been + // registered. + // + // java.nio.file.InvalidPathException: Illegal char <:> at index 4: ping:foo + if (resourceLoader instanceof FileSystemResourceLoader && OS.WINDOWS.isCurrentOs()) { assertThatExceptionOfType(InvalidPathException.class) .isThrownBy(() -> context.getResource(pingLocation)) .withMessageContaining(pingLocation);