4444import java .util .zip .ZipEntry ;
4545
4646import org .apache .commons .logging .LogFactory ;
47+ import org .junit .jupiter .api .AfterAll ;
48+ import org .junit .jupiter .api .BeforeAll ;
4749import org .junit .jupiter .api .Nested ;
4850import org .junit .jupiter .api .Test ;
4951import org .junit .jupiter .api .io .TempDir ;
@@ -298,8 +300,8 @@ void classpathStarWithPatternInJar() {
298300 @ Test
299301 void rootPatternRetrievalInJarFiles () throws IOException {
300302 assertThat (resolver .getResources ("classpath*:aspectj*.dtd" )).extracting (Resource ::getFilename )
301- .as ("Could not find aspectj_1_5_0.dtd in the root of the aspectjweaver jar" )
302- .containsExactly ("aspectj_1_5_0.dtd" );
303+ .as ("Could not find aspectj_1_5_0.dtd in the root of the aspectjweaver jar" )
304+ .containsExactly ("aspectj_1_5_0.dtd" );
303305 }
304306 }
305307
@@ -310,6 +312,16 @@ class ClassPathManifestEntries {
310312 @ TempDir
311313 Path temp ;
312314
315+ @ BeforeAll
316+ static void suppressJarCaches () {
317+ URLConnection .setDefaultUseCaches ("jar" , false );
318+ }
319+
320+ @ AfterAll
321+ static void restoreJarCaches () {
322+ URLConnection .setDefaultUseCaches ("jar" , true );
323+ }
324+
313325 @ Test
314326 void javaDashJarFindsClassPathManifestEntries () throws Exception {
315327 Path lib = this .temp .resolve ("lib" );
@@ -333,13 +345,22 @@ private void writeAssetJar(Path path) throws Exception {
333345 StreamUtils .copy ("test" , StandardCharsets .UTF_8 , jar );
334346 jar .closeEntry ();
335347 }
348+
336349 assertThat (new FileSystemResource (path ).exists ()).isTrue ();
337350 assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
338351 assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/file.txt" ).exists ()).isTrue ();
339352 assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/none.txt" ).exists ()).isFalse ();
340353 assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isFalse ();
341354 assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/file.txt" ).exists ()).isFalse ();
342355 assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + "X" + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/none.txt" ).exists ()).isFalse ();
356+
357+ Resource resource = new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR + "assets/file.txt" );
358+ try (InputStream is = resource .getInputStream ()) {
359+ assertThat (resource .exists ()).isTrue ();
360+ assertThat (resource .createRelative ("file.txt" ).exists ()).isTrue ();
361+ assertThat (new UrlResource (ResourceUtils .JAR_URL_PREFIX + ResourceUtils .FILE_URL_PREFIX + path + ResourceUtils .JAR_URL_SEPARATOR ).exists ()).isTrue ();
362+ is .readAllBytes ();
363+ }
343364 }
344365
345366 private void writeApplicationJar (Path path ) throws Exception {
0 commit comments