Skip to content

Commit f7b7649

Browse files
committed
Merge pull request #320 from beamerblvd/SPR-10770
# By Nick Williams * SPR-10770: Fix PathResourceTests on Windows
2 parents 9eb596a + e59c821 commit f7b7649

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

spring-core/src/test/java/org/springframework/core/io/PathResourceTests.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.file.Path;
2323
import java.nio.file.Paths;
2424

25+
import org.hamcrest.Matchers;
2526
import org.junit.Rule;
2627
import org.junit.Test;
2728
import org.junit.rules.ExpectedException;
@@ -37,14 +38,23 @@
3738
*
3839
* @author Philippe Marschall
3940
* @author Phillip Webb
41+
* @author Nicholas Williams
4042
*/
4143
public class PathResourceTests {
4244

43-
private static final String TEST_DIR = "src/test/java/org/springframework/core/io";
45+
private static final String TEST_DIR = platformPath("src/test/java/org/"
46+
+ "springframework/core/io");
4447

45-
private static final String TEST_FILE = "src/test/java/org/springframework/core/io/example.properties";
48+
private static final String TEST_FILE = platformPath("src/test/java/org/"
49+
+ "springframework/core/io/example.properties");
4650

47-
private static final String NON_EXISTING_FILE = "src/test/java/org/springframework/core/io/doesnotexist.properties";
51+
private static final String NON_EXISTING_FILE = platformPath("src/test/java/org/"
52+
+ "springframework/core/io/doesnotexist.properties");
53+
54+
55+
private static String platformPath(String string) {
56+
return string.replace('/', File.separatorChar);
57+
}
4858

4959

5060
@Rule
@@ -167,13 +177,13 @@ public void getInputStreamDoesNotExist() throws Exception {
167177
@Test
168178
public void getUrl() throws Exception {
169179
PathResource resource = new PathResource(TEST_FILE);
170-
assertTrue(resource.getURL().toString().endsWith(TEST_FILE));
180+
assertThat(resource.getURL().toString(), Matchers.endsWith("core/io/example.properties"));
171181
}
172182

173183
@Test
174184
public void getUri() throws Exception {
175185
PathResource resource = new PathResource(TEST_FILE);
176-
assertTrue(resource.getURI().toString().endsWith(TEST_FILE));
186+
assertThat(resource.getURI().toString(), Matchers.endsWith("core/io/example.properties"));
177187
}
178188

179189
@Test

0 commit comments

Comments
 (0)