Browse files

Replaced IllegalArgumentException for IOException

It's more consistent to throw an IOException instead of an
IllegalArgumentException
  • Loading branch information...
1 parent 59e5333 commit 2568203bdebd5a4a4ad9aa74b1d8369d22f668a3 Arjan Wulder committed Aug 13, 2012
View
8 src/main/java/org/junit/rules/TemporaryFolder.java
@@ -61,7 +61,7 @@ public void create() throws IOException {
public File newFile(String fileName) throws IOException {
File file= new File(getRoot(), fileName);
if (!file.createNewFile())
- throw new IllegalArgumentException(
+ throw new IOException(
"a file with the name \'" + fileName + "\' already exists in the test folder");
return file;
}
@@ -77,21 +77,21 @@ public File newFile() throws IOException {
* Returns a new fresh folder with the given name under the temporary
* folder.
*/
- public File newFolder(String folder) {
+ public File newFolder(String folder) throws IOException {
return newFolder(new String[]{folder});
}
/**
* Returns a new fresh folder with the given name(s) under the temporary
* folder.
*/
- public File newFolder(String... folderNames) {
+ public File newFolder(String... folderNames) throws IOException {
File file= getRoot();
for (int i = 0; i < folderNames.length; i++) {
String folderName = folderNames[i];
file = new File(file, folderName);
if (!file.mkdir() && isLastElementInArray(i, folderNames))
- throw new IllegalArgumentException(
+ throw new IOException(
"a folder with the name \'" + folderName + "\' already exists");
}
return file;
View
2 src/test/java/org/junit/tests/experimental/rules/TempFolderRuleTest.java
@@ -217,7 +217,7 @@ public void testNewFile() throws IOException {
}
@Test
- public void testNewFolder() {
+ public void testNewFolder() throws IOException {
folder.newFolder(NEW_FOLDER_DUMMY);
}
}
View
8 src/test/java/org/junit/tests/experimental/rules/TemporaryFolderUsageTest.java
@@ -59,7 +59,7 @@ public void newFileWithGivenFilenameThrowsIllegalArgumentExceptionIfFileExists()
tempFolder.create();
tempFolder.newFile("MyFile.txt");
- thrown.expect(IllegalArgumentException.class);
+ thrown.expect(IOException.class);
thrown.expectMessage("a file with the name 'MyFile.txt' already exists in the test folder");
tempFolder.newFile("MyFile.txt");
}
@@ -71,7 +71,7 @@ public void newFolderThrowsIllegalStateExceptionIfCreateWasNotInvoked()
}
@Test(expected= IllegalStateException.class)
- public void newFolderWithGivenPathThrowsIllegalStateExceptionIfCreateWasNotInvoked() {
+ public void newFolderWithGivenPathThrowsIllegalStateExceptionIfCreateWasNotInvoked() throws IOException {
new TemporaryFolder().newFolder("level1", "level2", "level3");
}
@@ -80,7 +80,7 @@ public void newFolderWithGivenFolderThrowsIllegalArgumentExceptionIfFolderExists
tempFolder.create();
tempFolder.newFolder("level1");
- thrown.expect(IllegalArgumentException.class);
+ thrown.expect(IOException.class);
thrown.expectMessage("a folder with the name 'level1' already exists");
tempFolder.newFolder("level1");
}
@@ -90,7 +90,7 @@ public void newFolderWithGivenPathThrowsIllegalArgumentExceptionIfPathExists() t
tempFolder.create();
tempFolder.newFolder("level1", "level2", "level3");
- thrown.expect(IllegalArgumentException.class);
+ thrown.expect(IOException.class);
thrown.expectMessage("a folder with the name 'level3' already exists");
tempFolder.newFolder("level1", "level2", "level3");
}

0 comments on commit 2568203

Please sign in to comment.