Some tests fail if the base path contains a space
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -47,6 +47,9 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<!-- The release date is the date RC is cut -->
<release version="2.7" date="tba" description="tba">
+ <action issue="IO-589" dev="sebb" type="fix">
+ Some tests fail if the base path contains a space
+ </action>
<action dev="jochen" type="add">
Adding the CircularBufferInputStream, and the PeekableInputStream.
</action>

MODIFY
src/test/java/org/apache/commons/io/FileUtilsTestCase.java
src/test/java/org/apache/commons/io/FileUtilsTestCase.java
@@ -668,17 +668,17 @@ public void testContentEqualsIgnoreEOL() throws Exception {
final URL urlCR = getClass().getResource("FileUtilsTestDataCR.dat");
assertNotNull(urlCR);
- final File cr = new File(urlCR.getPath());
+ final File cr = new File(urlCR.toURI());
assertTrue(cr.exists());
final URL urlCRLF = getClass().getResource("FileUtilsTestDataCRLF.dat");
assertNotNull(urlCRLF);
- final File crlf = new File(urlCRLF.getPath());
+ final File crlf = new File(urlCRLF.toURI());
assertTrue(crlf.exists());
final URL urlLF = getClass().getResource("FileUtilsTestDataLF.dat");
assertNotNull(urlLF);
- final File lf = new File(urlLF.getPath());
+ final File lf = new File(urlLF.toURI());
assertTrue(lf.exists());
assertTrue(FileUtils.contentEqualsIgnoreEOL(cr, cr, null));

MODIFY
src/test/java/org/apache/commons/io/IOUtilsTestCase.java
src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -1161,7 +1161,7 @@ private void testToString_URL(final String encoding) throws Exception {
}
@Test public void testResourceToString_ExistingResourceAtRootPackage() throws Exception {
- final long fileSize = new File(getClass().getResource("/test-file-simple-utf8.bin").getFile()).length();
+ final long fileSize = new File(getClass().getResource("/test-file-simple-utf8.bin").toURI()).length();
final String content = IOUtils.resourceToString("/test-file-simple-utf8.bin", StandardCharsets.UTF_8);
assertNotNull(content);
@@ -1169,7 +1169,7 @@ private void testToString_URL(final String encoding) throws Exception {
}
@Test public void testResourceToString_ExistingResourceAtRootPackage_WithClassLoader() throws Exception {
- final long fileSize = new File(getClass().getResource("/test-file-simple-utf8.bin").getFile()).length();
+ final long fileSize = new File(getClass().getResource("/test-file-simple-utf8.bin").toURI()).length();
final String content = IOUtils.resourceToString(
"test-file-simple-utf8.bin",
StandardCharsets.UTF_8,
@@ -1181,7 +1181,7 @@ private void testToString_URL(final String encoding) throws Exception {
}
@Test public void testResourceToString_ExistingResourceAtSubPackage() throws Exception {
- final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").getFile()).length();
+ final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").toURI()).length();
final String content = IOUtils.resourceToString("/org/apache/commons/io/FileUtilsTestDataCR.dat", StandardCharsets.UTF_8);
assertNotNull(content);
@@ -1189,7 +1189,7 @@ private void testToString_URL(final String encoding) throws Exception {
}
@Test public void testResourceToString_ExistingResourceAtSubPackage_WithClassLoader() throws Exception {
- final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").getFile()).length();
+ final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").toURI()).length();
final String content = IOUtils.resourceToString(
"org/apache/commons/io/FileUtilsTestDataCR.dat",
StandardCharsets.UTF_8,
@@ -1245,28 +1245,28 @@ private void testToString_URL(final String encoding) throws Exception {
}
@Test public void testResourceToByteArray_ExistingResourceAtRootPackage() throws Exception {
- final long fileSize = new File(getClass().getResource("/test-file-utf8.bin").getFile()).length();
+ final long fileSize = new File(getClass().getResource("/test-file-utf8.bin").toURI()).length();
final byte[] bytes = IOUtils.resourceToByteArray("/test-file-utf8.bin");
assertNotNull(bytes);
assertEquals(fileSize, bytes.length);
}
@Test public void testResourceToByteArray_ExistingResourceAtRootPackage_WithClassLoader() throws Exception {
- final long fileSize = new File(getClass().getResource("/test-file-utf8.bin").getFile()).length();
+ final long fileSize = new File(getClass().getResource("/test-file-utf8.bin").toURI()).length();
final byte[] bytes = IOUtils.resourceToByteArray("test-file-utf8.bin", ClassLoader.getSystemClassLoader());
assertNotNull(bytes);
assertEquals(fileSize, bytes.length);
}
@Test public void testResourceToByteArray_ExistingResourceAtSubPackage() throws Exception {
- final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").getFile()).length();
+ final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").toURI()).length();
final byte[] bytes = IOUtils.resourceToByteArray("/org/apache/commons/io/FileUtilsTestDataCR.dat");
assertNotNull(bytes);
assertEquals(fileSize, bytes.length);
}
@Test public void testResourceToByteArray_ExistingResourceAtSubPackage_WithClassLoader() throws Exception {
- final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").getFile()).length();
+ final long fileSize = new File(getClass().getResource("/org/apache/commons/io/FileUtilsTestDataCR.dat").toURI()).length();
final byte[] bytes = IOUtils.resourceToByteArray("org/apache/commons/io/FileUtilsTestDataCR.dat", ClassLoader.getSystemClassLoader());
assertNotNull(bytes);
assertEquals(fileSize, bytes.length);

IO-589 Some tests fail if the base path contains a space