Skip to content

Commit fa1b22f

Browse files
committed
Merge branch '3.3.x' into 3.4.x
Closes gh-45402
2 parents 7514f84 + 0f5abaf commit fa1b22f

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/StandardConfigDataResourceTests.java

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,9 +17,14 @@
1717
package org.springframework.boot.context.config;
1818

1919
import java.io.IOException;
20+
import java.net.URL;
21+
import java.net.URLClassLoader;
22+
import java.nio.file.Path;
2023

2124
import org.junit.jupiter.api.Test;
2225

26+
import org.springframework.boot.testsupport.classpath.resources.ResourcePath;
27+
import org.springframework.boot.testsupport.classpath.resources.WithResource;
2328
import org.springframework.core.io.ClassPathResource;
2429
import org.springframework.core.io.FileUrlResource;
2530
import org.springframework.core.io.Resource;
@@ -70,14 +75,24 @@ void equalsWhenResourceIsDifferentReturnsFalse() {
7075
}
7176

7277
@Test // gh-34212
73-
void equalsAndHashCodeWhenSameUnderlyingResource() throws IOException {
74-
ClassPathResource classPathResource = new ClassPathResource("log4j2.springboot");
75-
FileUrlResource fileUrlResource = new FileUrlResource(classPathResource.getURL());
76-
ConfigDataResource classPathConfigDataResource = new StandardConfigDataResource(this.reference,
77-
classPathResource);
78-
ConfigDataResource fileUrlConfigDataResource = new StandardConfigDataResource(this.reference, fileUrlResource);
79-
assertThat(classPathConfigDataResource.hashCode()).isEqualTo(fileUrlConfigDataResource.hashCode());
80-
assertThat(classPathConfigDataResource).isEqualTo(fileUrlConfigDataResource);
78+
@WithResource(name = "test.resource", content = "test")
79+
void equalsAndHashCodeWhenSameUnderlyingResource(@ResourcePath("test.resource") Path path) throws IOException {
80+
Path directory = path.getParent();
81+
URLClassLoader classLoader = new URLClassLoader(new URL[] { directory.toUri().toURL() },
82+
getClass().getClassLoader());
83+
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
84+
Thread.currentThread().setContextClassLoader(classLoader);
85+
try {
86+
ClassPathResource classResource = new ClassPathResource("test.resource", classLoader);
87+
FileUrlResource fileResource = new FileUrlResource(classResource.getURL());
88+
ConfigDataResource classDataResource = new StandardConfigDataResource(this.reference, classResource);
89+
ConfigDataResource fileDataResource = new StandardConfigDataResource(this.reference, fileResource);
90+
assertThat(classDataResource.hashCode()).isEqualTo(fileDataResource.hashCode());
91+
assertThat(classDataResource).isEqualTo(fileDataResource);
92+
}
93+
finally {
94+
Thread.currentThread().setContextClassLoader(contextClassLoader);
95+
}
8196
}
8297

8398
}

0 commit comments

Comments
 (0)