Permalink
Browse files

Issue 478: Throw an IllegalStateException when the folder already exists

Changed the code so it behaves like it is described in the
documentation.
  • Loading branch information...
Arjan Wulder
Arjan Wulder committed Aug 12, 2012
1 parent 26caa86 commit 6012fa3b4fe4e924311d42e05e216092e425cbf9
@@ -89,7 +89,9 @@ public File newFolder(String... folderNames) {
File file= getRoot();
for (String folderName : folderNames) {
file= new File(file, folderName);
- file.mkdir();
+ if (!file.mkdir())
+ throw new IllegalStateException(
+ "a folder with the name \'" + folderName + "\' already exists");
}
return file;
}
@@ -54,7 +54,14 @@ public void newFolderThrowsIllegalStateExceptionIfCreateWasNotInvoked()
@Test(expected= IllegalStateException.class)
public void newFolderWithGivenPathThrowsIllegalStateExceptionIfCreateWasNotInvoked() {
- new TemporaryFolder().newFolder("level1", "leve2", "leve3");
+ new TemporaryFolder().newFolder("level1", "level2", "level3");
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void newFolderWithGivenPathThrowsIllegalStateExceptionIfPathExists() throws IOException {
+ tempFolder.create();
+ tempFolder.newFolder("level1", "level2", "level3");
+ tempFolder.newFolder("level1", "level2", "level3");
}
@Test

0 comments on commit 6012fa3

Please sign in to comment.