Skip to content

Commit dcf160e

Browse files
committed
Consistently include leading slash for classpath: resources in the TCF
1 parent 920fbb3 commit dcf160e

File tree

5 files changed

+13
-7
lines changed

5 files changed

+13
-7
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -98,6 +98,8 @@
9898
*/
9999
public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListener {
100100

101+
private static final String SLASH = "/";
102+
101103
private static final Log logger = LogFactory.getLog(SqlScriptsTestExecutionListener.class);
102104

103105

@@ -343,7 +345,7 @@ private String detectDefaultScript(TestContext testContext, boolean classLevel)
343345
}
344346
resourcePath += ".sql";
345347

346-
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
348+
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + SLASH + resourcePath;
347349
ClassPathResource classPathResource = new ClassPathResource(resourcePath);
348350

349351
if (classPathResource.exists()) {

spring-test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
*/
6868
public abstract class AbstractContextLoader implements SmartContextLoader {
6969

70+
private static final String SLASH = "/";
71+
7072
private static final String[] EMPTY_STRING_ARRAY = new String[0];
7173

7274
private static final Log logger = LogFactory.getLog(AbstractContextLoader.class);
@@ -252,7 +254,7 @@ protected String[] generateDefaultLocations(Class<?> clazz) {
252254
String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName()) + suffix;
253255
ClassPathResource classPathResource = new ClassPathResource(resourcePath);
254256
if (classPathResource.exists()) {
255-
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
257+
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + SLASH + resourcePath;
256258
if (logger.isInfoEnabled()) {
257259
logger.info(String.format("Detected default resource location \"%s\" for test class [%s]",
258260
prefixedResourcePath, clazz.getName()));

spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceAttributes.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -50,6 +50,8 @@
5050
*/
5151
class TestPropertySourceAttributes {
5252

53+
private static final String SLASH = "/";
54+
5355
private static final Log logger = LogFactory.getLog(TestPropertySourceAttributes.class);
5456

5557

@@ -156,7 +158,7 @@ private String detectDefaultPropertiesFile(Class<?> testClass) {
156158
logger.error(msg);
157159
throw new IllegalStateException(msg);
158160
}
159-
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
161+
String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + SLASH + resourcePath;
160162
if (logger.isInfoEnabled()) {
161163
logger.info(String.format("Detected default properties file \"%s\" for test class [%s]",
162164
prefixedResourcePath, testClass.getName()));

spring-test/src/test/java/org/springframework/test/context/support/BootstrapTestUtilsMergedConfigTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void buildMergedConfigWithBareAnnotations() {
7373
assertMergedConfig(
7474
mergedConfig,
7575
testClass,
76-
array("classpath:org/springframework/test/context/support/AbstractContextConfigurationUtilsTests$BareAnnotations-context.xml"),
76+
array("classpath:/org/springframework/test/context/support/AbstractContextConfigurationUtilsTests$BareAnnotations-context.xml"),
7777
EMPTY_CLASS_ARRAY, DelegatingSmartContextLoader.class);
7878
}
7979

spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static Stream<Arguments> contextConfigurationLocationsData() {
7878
args(ClasspathNonExistentDefaultLocationsTestCase.class, array()),
7979

8080
args(ClasspathExistentDefaultLocationsTestCase.class, array(
81-
"classpath:org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests$ClasspathExistentDefaultLocationsTestCase-context.xml")),
81+
"classpath:/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests$ClasspathExistentDefaultLocationsTestCase-context.xml")),
8282

8383
args(ImplicitClasspathLocationsTestCase.class,
8484
array("classpath:/org/springframework/test/context/support/context1.xml",

0 commit comments

Comments
 (0)