Skip to content

Commit 6902ff7

Browse files
committed
Fix resource registration hints in the TestContext framework
Resource patterns registered for inclusion in a GraalVM native image must not start with a leading slash.
1 parent 6e93f11 commit 6902ff7

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

spring-test/src/main/java/org/springframework/test/context/aot/hint/StandardTestRuntimeHints.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ private void registerClasspathResourceDirectoryStructure(RuntimeHints runtimeHin
114114

115115
private String cleanClasspathResource(String location) {
116116
location = location.substring(CLASSPATH_URL_PREFIX.length());
117-
if (!location.startsWith(SLASH)) {
118-
location = SLASH + location;
117+
if (location.startsWith(SLASH)) {
118+
location = location.substring(1);
119119
}
120120
return location;
121121
}

spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ private void registerClasspathResources(RuntimeHints runtimeHints, String... loc
399399

400400
private String cleanClasspathResource(String location) {
401401
location = location.substring(CLASSPATH_URL_PREFIX.length());
402-
if (!location.startsWith(SLASH)) {
403-
location = SLASH + location;
402+
if (location.startsWith(SLASH)) {
403+
location = location.substring(1);
404404
}
405405
return location;
406406
}

spring-test/src/test/java/org/springframework/test/context/aot/TestContextAotGeneratorTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,21 @@ private static void assertRuntimeHints(RuntimeHints runtimeHints) {
181181
).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS));
182182

183183
// @ContextConfiguration(locations = ...)
184-
assertThat(resource().forResource("/org/springframework/test/context/aot/samples/xml/test-config.xml"))
184+
assertThat(resource().forResource("org/springframework/test/context/aot/samples/xml/test-config.xml"))
185185
.accepts(runtimeHints);
186186

187187
// @TestPropertySource(locations = ...)
188-
assertThat(resource().forResource("/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties"))
188+
assertThat(resource().forResource("org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties"))
189189
.accepts(runtimeHints);
190190

191191
// @WebAppConfiguration(value = ...)
192-
assertThat(resource().forResource("/META-INF/web-resources/resources/Spring.js")).accepts(runtimeHints);
193-
assertThat(resource().forResource("/META-INF/web-resources/WEB-INF/views/home.jsp")).accepts(runtimeHints);
192+
assertThat(resource().forResource("META-INF/web-resources/resources/Spring.js")).accepts(runtimeHints);
193+
assertThat(resource().forResource("META-INF/web-resources/WEB-INF/views/home.jsp")).accepts(runtimeHints);
194194

195195
// @Sql(scripts = ...)
196-
assertThat(resource().forResource("/org/springframework/test/context/jdbc/schema.sql"))
196+
assertThat(resource().forResource("org/springframework/test/context/jdbc/schema.sql"))
197197
.accepts(runtimeHints);
198-
assertThat(resource().forResource("/org/springframework/test/context/aot/samples/jdbc/SqlScriptsSpringJupiterTests.test.sql"))
198+
assertThat(resource().forResource("org/springframework/test/context/aot/samples/jdbc/SqlScriptsSpringJupiterTests.test.sql"))
199199
.accepts(runtimeHints);
200200
}
201201

0 commit comments

Comments
 (0)