Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

TemporaryFolder.newFile should fail if file already exists (fixes #413)

  • Loading branch information...
commit 5baa714c5fe4d16dca9dea8c73c6d8702dfd71f2 1 parent c4279e4
@simplyarjen simplyarjen authored
View
4 src/main/java/org/junit/rules/TemporaryFolder.java
@@ -50,7 +50,9 @@ public void create() throws IOException {
*/
public File newFile(String fileName) throws IOException {
File file= new File(getRoot(), fileName);
- file.createNewFile();
+ if (!file.createNewFile())
+ throw new IllegalStateException(
+ "a file with the name \'" + fileName + "\' already exists in the test folder");
return file;
}
View
22 src/test/java/org/junit/tests/experimental/rules/TempFolderRuleTest.java
@@ -158,6 +158,28 @@ public void recursiveDeleteFolderWithZeroElements() throws IOException {
assertFalse(folder.getRoot().exists());
}
+ public static class NameClashes {
+ @Rule
+ public TemporaryFolder folder= new TemporaryFolder();
+
+ @Test
+ public void fileWithFileClash() throws IOException {
+ folder.newFile("something.txt");
+ folder.newFile("something.txt");
+ }
+
+ @Test
+ public void fileWithFolderTest() throws IOException {
+ folder.newFolder("dummy");
+ folder.newFile("dummy");
+ }
+ }
+
+ @Test
+ public void nameClashesResultInTestFailures() {
+ assertThat(testResult(NameClashes.class), failureCountIs(2));
+ }
+
private static final String GET_ROOT_DUMMY= "dummy-getRoot";
private static final String NEW_FILE_DUMMY= "dummy-newFile";
Please sign in to comment.
Something went wrong with that request. Please try again.