[FIXED JENKINS-17271] Util.deleteFile should give a concrete reason for failure.

This commit is contained in:
Jesse Glick committed 2013-03-19 11:05:21 -04:00
1 parent 606a9e1de9
commit 78b263421f
3 files changed
+43 -1

No files matched your search

+28
View File
@@ -37,6 +37,9 @@ import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import hudson.util.StreamTaskListener;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.junit.internal.AssumptionViolatedException;
/**
* @author Kohsuke Kawaguchi
@@ -230,6 +233,31 @@ public class UtilTest {
}
}
@Test public void deleteFile() throws Exception {
Assume.assumeTrue(Functions.isWindows());
Class<?> c;
try {
c = Class.forName("java.nio.file.FileSystemException");
} catch (ClassNotFoundException x) {
throw new AssumptionViolatedException("prior to JDK 7", x);
}
File d = Util.createTempDir();
try {
File f = new File(d, "f");
OutputStream os = new FileOutputStream(f);
try {
Util.deleteFile(f);
fail("should not have been deletable");
} catch (IOException x) {
assertEquals(c, x.getClass());
} finally {
os.close();
}
} finally {
Util.deleteRecursive(d);
}
}
@Test
public void testHtmlEscape() {
assertEquals("<br>", Util.escape("\n"));