Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.10 - Recursive temp folders #283

Merged
merged 3 commits into from
Aug 11, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions acknowledgements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@
2011 Jun 24
Samuel Le Berrigaud (sleberrigaud@github): Report for GH-248:
protected BlockJUnit4ClassRunner#rules method removed from 4.8.2

2011 Aug 10
rodolfoliviero@github and JoseRibeiro@github: feature to create recursive temporary folders.
9 changes: 6 additions & 3 deletions src/main/java/org/junit/rules/TemporaryFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,36 @@ public static class CreatesSubFolder {

@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();
}
}

Expand Down