@FunctionalInterface
@API(status=EXPERIMENTAL,
since="5.10")
public interface TempDirFactory
extends java.io.Closeable
TempDirFactory defines the SPI for creating temporary directories
programmatically.
A temporary directory factory is typically used to gain control over the temporary directory creation, like defining the parent directory or the file system that should be used.
Implementations must provide a no-args constructor and should not make any
assumptions regarding when and how many times they are instantiated, but they
can assume that createTempDirectory(AnnotatedElementContext, ExtensionContext)
and close() will both be called once per instance, in this order,
and from the same thread.
A TempDirFactory can be configured globally for the
entire test suite via the
configuration parameter (see the User Guide for details) or locally
for a test class field or method parameter via the @TempDir
annotation.
@TempDir| Modifier and Type | Interface and Description |
|---|---|
static class |
TempDirFactory.Standard
Standard
TempDirFactory implementation which delegates to
Files.createTempDirectory(java.nio.file.Path, java.lang.String, java.nio.file.attribute.FileAttribute<?>...) using "junit" as the prefix. |
| Modifier and Type | Method and Description |
|---|---|
default void |
close() |
java.nio.file.Path |
createTempDirectory(AnnotatedElementContext elementContext,
ExtensionContext extensionContext)
Create a new temporary directory.
|
java.nio.file.Path createTempDirectory(AnnotatedElementContext elementContext, ExtensionContext extensionContext) throws java.lang.Exception
Depending on the implementation, the resulting Path may or may
not be associated with the default FileSystem.
elementContext - the context of the field or parameter where
@TempDir is declared; never nullextensionContext - the current extension context; never nullnulljava.lang.Exception - in case of failuresdefault void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOException