public class TemporaryFolder extends ExternalResource
Example of usage:
public static class HasTempFolder {
@Rule
public TemporaryFolder folder= new TemporaryFolder();
@Test
public void testUsingTempFolder() throws IOException {
File createdFile= folder.newFile("myfile.txt");
File createdFolder= folder.newFolder("subfolder");
// ...
}
}
| Constructor and Description |
|---|
TemporaryFolder() |
TemporaryFolder(java.io.File parentFolder) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
after()
Override to tear down your specific external resource.
|
protected void |
before()
Override to set up your specific external resource.
|
void |
create()
for testing purposes only.
|
void |
delete()
Delete all files and folders under the temporary folder.
|
java.io.File |
getRoot() |
java.io.File |
newFile()
Returns a new fresh file with a random name under the temporary folder.
|
java.io.File |
newFile(java.lang.String fileName)
Returns a new fresh file with the given name under the temporary folder.
|
java.io.File |
newFolder()
Returns a new fresh folder with a random name under the temporary folder.
|
java.io.File |
newFolder(java.lang.String... folderNames)
Returns a new fresh folder with the given name(s) under the temporary
folder.
|
java.io.File |
newFolder(java.lang.String folder)
Returns a new fresh folder with the given name under the temporary
folder.
|
applypublic TemporaryFolder()
public TemporaryFolder(java.io.File parentFolder)
protected void before()
throws java.lang.Throwable
ExternalResourcebefore in class ExternalResourcejava.lang.Throwable - if setup fails (which will disable afterprotected void after()
ExternalResourceafter in class ExternalResourcepublic void create()
throws java.io.IOException
java.io.IOExceptionpublic java.io.File newFile(java.lang.String fileName)
throws java.io.IOException
java.io.IOExceptionpublic java.io.File newFile()
throws java.io.IOException
java.io.IOExceptionpublic java.io.File newFolder(java.lang.String folder)
throws java.io.IOException
java.io.IOExceptionpublic java.io.File newFolder(java.lang.String... folderNames)
throws java.io.IOException
java.io.IOExceptionpublic java.io.File newFolder()
throws java.io.IOException
java.io.IOExceptionpublic java.io.File getRoot()
public void delete()
Rule