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

Fixes #441 fix for issue 283 (recursive temp folders) caused incompatibility #454

Merged
merged 1 commit into from
Jun 23, 2012
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
10 changes: 9 additions & 1 deletion src/main/java/org/junit/rules/TemporaryFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void after() {
* for testing purposes only. Do not use.
*/
public void create() throws IOException {
folder = createTemporaryFolderIn(parentFolder);
folder= createTemporaryFolderIn(parentFolder);
}

/**
Expand All @@ -77,6 +77,14 @@ public File newFile() throws IOException {
* Returns a new fresh folder with the given name under the temporary
* folder.
*/
public File newFolder(String folder) {
return newFolder(new String[]{folder});
}

/**
* Returns a new fresh folder with the given name(s) under the temporary
* folder.
*/
public File newFolder(String... folderNames) {
File file= getRoot();
for (String folderName : folderNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;

import org.junit.After;
Expand Down Expand Up @@ -43,14 +44,30 @@ public static class CreatesSubFolder {
public TemporaryFolder folder= new TemporaryFolder();

@Test
public void testUsingTempFolder() throws IOException {
public void testUsingTempFolderStringReflection() throws Exception {
String subfolder = "subfolder";
String filename = "a.txt";
// force usage of folder.newFolder(String),
// check is available and works, to avoid a potential NoSuchMethodError with non-recompiled code.
Method method = folder.getClass().getMethod("newFolder", new Class<?>[] {String.class});
createdFiles[0]= (File) method.invoke(folder, subfolder);
new File(createdFiles[0], filename).createNewFile();

File expectedFile = new File(folder.getRoot(), join(subfolder, filename));

assertTrue(expectedFile.exists());
}

@Test
public void testUsingTempFolderString() throws IOException {
String subfolder = "subfolder";
String filename = "a.txt";
// this uses newFolder(String), ensure that a single String works
createdFiles[0]= folder.newFolder(subfolder);
new File(createdFiles[0], filename).createNewFile();

File expectedFile = new File(folder.getRoot(), join(subfolder, filename));

assertTrue(expectedFile.exists());
}

Expand Down