Interface TempDirFactory
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable
- All Known Implementing Classes:
TempDirFactory.Standard
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface @API(status=MAINTAINED, since="5.13.3") public interface TempDirFactory extends java.io.CloseableTempDirFactorydefines 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)andclose()will both be called once per instance, in this order, and from the same thread.A
TempDirFactorycan be configured globally for the entire test suite via the "junit.jupiter.tempdir.factory.default" configuration parameter (see the User Guide for details) or locally for a test class field or method parameter via the@TempDirannotation.- Since:
- 5.10
- See Also:
@TempDir
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classTempDirFactory.StandardStandardTempDirFactoryimplementation which delegates toFiles.createTempDirectory(java.nio.file.Path, java.lang.String, java.nio.file.attribute.FileAttribute<?>...)using"junit-"as prefix.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidclose()java.nio.file.PathcreateTempDirectory(AnnotatedElementContext elementContext, ExtensionContext extensionContext)Create a new temporary directory.
-
-
-
Method Detail
-
createTempDirectory
java.nio.file.Path createTempDirectory(AnnotatedElementContext elementContext, ExtensionContext extensionContext) throws java.lang.Exception
Create a new temporary directory.Depending on the implementation, the resulting
Pathmay or may not be associated with thedefault FileSystem.- Parameters:
elementContext- the context of the field or parameter where@TempDiris declared; nevernullextensionContext- the current extension context; nevernull- Returns:
- the path to the newly created temporary directory; never
null - Throws:
java.lang.Exception- in case of failures
-
close
default void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-