diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2010-12-30 23:10:55 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2011-01-14 17:28:14 +0100 |
commit | c45f2aec56a323a55119de0d17951fdb302f1c72 (patch) | |
tree | e730a1c0e65f113e3d37ea890d8937d2fb1b8e6d /org.eclipse.jgit.test/tst | |
parent | 05ca0c49f90842da9ad81a0d5a5b91e834648073 (diff) | |
download | jgit-c45f2aec56a323a55119de0d17951fdb302f1c72.tar.gz jgit-c45f2aec56a323a55119de0d17951fdb302f1c72.zip |
File utility for creating a new empty file
The java.io.File.createNewFile() method for creating new empty files
reports failure by returning false. To ease proper checking of return
values provide a utility method wrapping createNewFile() throwing
IOException on failure.
Change-Id: I42a3dc9d8ff70af62e84de396e6a740050afa896
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java index 4ad4234868..d81e686c14 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilTest.java @@ -175,4 +175,19 @@ public class FileUtilTest { assertTrue(f.delete()); } + public void testCreateNewFile() throws IOException { + File f = new File(trash, "x"); + FileUtils.createNewFile(f); + assertTrue(f.exists()); + + try { + FileUtils.createNewFile(f); + fail("creation of already existing file must fail"); + } catch (IOException e) { + // expected + } + + FileUtils.delete(f); + } + } |