Skip to content

Commit a809c5d

Browse files
author
Stephen Colebourne
committed
IO-107 - Increase test robustness for openOutputStream
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@490988 13f79535-47bb-0310-9956-ffa450edef68
1 parent 4bc539c commit a809c5d

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/test/org/apache/commons/io/FileUtilsTestCase.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ public void test_openOutputStream_exists() throws Exception {
119119
public void test_openOutputStream_existsButIsDirectory() throws Exception {
120120
File directory = new File(getTestDirectory(), "subdir");
121121
directory.mkdirs();
122+
FileOutputStream out = null;
122123
try {
123-
FileUtils.openOutputStream(directory);
124+
out = FileUtils.openOutputStream(directory);
124125
fail();
125126
} catch (IOException ioe) {
126127
// expected
128+
} finally {
129+
IOUtils.closeQuietly(out);
127130
}
128131
}
129132

@@ -140,12 +143,23 @@ public void test_openOutputStream_notExists() throws Exception {
140143
}
141144

142145
public void test_openOutputStream_notExistsCannotCreate() throws Exception {
143-
File file = new File(getTestDirectory(), "a/:#$!/test.txt"); // empty path segment is bad directory name
146+
// according to Wikipedia, most filing systems have a 256 limit on filename
147+
String longStr =
148+
"abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
149+
"abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
150+
"abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
151+
"abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
152+
"abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
153+
"abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz"; // 300 chars
154+
File file = new File(getTestDirectory(), "a/" + longStr + "/test.txt");
155+
FileOutputStream out = null;
144156
try {
145-
FileUtils.openOutputStream(file);
157+
out = FileUtils.openOutputStream(file);
146158
fail();
147159
} catch (IOException ioe) {
148160
// expected
161+
} finally {
162+
IOUtils.closeQuietly(out);
149163
}
150164
}
151165

0 commit comments

Comments
 (0)