Skip to content

Commit

Permalink
newFolder(String...) now throws IAE on an empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
kcooney committed Jan 10, 2017
1 parent fc2f040 commit 741571f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/junit/rules/TemporaryFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,15 @@ public File newFolder(String path) throws IOException {
* {@code "parent"} directory.
*/
public File newFolder(String... paths) throws IOException {
// Before checking the paths, check if create() was ever called, and if it wasn't, throw
File root = getRoot();
if (paths.length == 0) {
throw new IllegalArgumentException("must pass at least one path");
}

/*
* Before checking if the paths are absolute paths, check if create() was ever called,
* and if it wasn't, throw IllegalStateException.
*/
File root = getRoot();
for (String path : paths) {
if (new File(path).isAbsolute()) {
throw new IOException("folder path \'" + path + "\' is not a relative path");
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/junit/rules/TemporaryFolderUsageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ public void newFolderWithGivenPathThrowsIllegalArgumentExceptionIfFolderExists()
tempFolder.newFolder("level1", "level2", "level3");
}

@Test
public void newFolderWithGivenEmptyArrayThrowsIllegalArgumentException() throws IOException {
tempFolder.create();

thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("must pass at least one path");
tempFolder.newFolder(new String[0]);
}

@Test
public void newFolderWithPathsContainingForwardSlashCreatesFullPath()
throws IOException {
Expand Down

0 comments on commit 741571f

Please sign in to comment.