diff --git a/src/main/java/org/junit/rules/TemporaryFolder.java b/src/main/java/org/junit/rules/TemporaryFolder.java index beecb8dfb9ec..cd42b3cf124b 100644 --- a/src/main/java/org/junit/rules/TemporaryFolder.java +++ b/src/main/java/org/junit/rules/TemporaryFolder.java @@ -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"); diff --git a/src/test/java/org/junit/rules/TemporaryFolderUsageTest.java b/src/test/java/org/junit/rules/TemporaryFolderUsageTest.java index 6796a788d0a2..cfa476536b80 100644 --- a/src/test/java/org/junit/rules/TemporaryFolderUsageTest.java +++ b/src/test/java/org/junit/rules/TemporaryFolderUsageTest.java @@ -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 {