Skip to content
Browse files

Merge pull request #454 from matthewfarwell/fix-441-recursive-temp-fo…

…lders

Fixes #441 fix for issue 283 (recursive temp folders) caused incompatibility
  • Loading branch information...
2 parents e8b91fa + 67e43ab commit 28938e9c677dd4cf343ec4fcca9a668b5e930324 @kcooney kcooney committed Jun 23, 2012
View
10 src/main/java/org/junit/rules/TemporaryFolder.java
@@ -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);
}
/**
@@ -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) {
View
23 src/test/java/org/junit/tests/experimental/rules/TempFolderRuleTest.java
@@ -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;
@@ -43,14 +44,30 @@ public void tempFolderIsDeleted() {
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());
}

0 comments on commit 28938e9

Please sign in to comment.
Something went wrong with that request. Please try again.