Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

temporary tree folders

  • Loading branch information...
commit b00a3cdcaaf0bb554ed0955f98d9f1d759710c27 1 parent d0d4772
@rodolfoliviero rodolfoliviero authored
View
9 src/main/java/org/junit/rules/TemporaryFolder.java
@@ -59,9 +59,12 @@ public File newFile(String fileName) throws IOException {
/**
* Returns a new fresh folder with the given name under the temporary folder.
*/
- public File newFolder(String folderName) {
- File file= new File(folder, folderName);
- file.mkdir();
+ public File newFolder(String... folderNames) {
+ File file = folder;
+ for (String folderName : folderNames) {
+ file = new File(file, folderName);
+ file.mkdir();
+ }
return file;
}
View
33 src/test/java/org/junit/tests/experimental/rules/TempFolderRuleTest.java
@@ -39,9 +39,36 @@ public void tempFolderIsDeleted() {
@Test
public void testUsingTempFolder() throws IOException {
- createdFile= folder.newFolder("subfolder");
- new File(createdFile, "a.txt").createNewFile();
- assertTrue(createdFile.exists());
+ String subfolder = "subfolder";
+ String filename = "a.txt";
+ createdFile= folder.newFolder(subfolder);
+ new File(createdFile, filename).createNewFile();
+
+ File expectedFile = new File(folder.getRoot(), join(subfolder, filename));
+
+ assertTrue(expectedFile.exists());
+ }
+
+ @Test
+ public void testUsingTempTreeFolders() throws IOException {
+ String subfolder = "subfolder";
+ String anotherfolder = "anotherfolder";
+ String filename = "a.txt";
+
+ createdFile = folder.newFolder(subfolder, anotherfolder);
+ new File(createdFile, filename).createNewFile();
+
+ File expectedFile = new File(folder.getRoot(), join(subfolder, anotherfolder, filename));
+
+ assertTrue(expectedFile.exists());
+ }
+
+ private String join(String... folderNames) {
+ StringBuilder path = new StringBuilder();
+ for (String folderName : folderNames) {
+ path.append(File.separator).append(folderName);
+ }
+ return path.toString();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.