Top Description Inners Methods
org.junit.jupiter.api.io

public Interface TempDirFactory

extends Closeable
Known Direct Implementers
org.junit.jupiter.api.io.TempDirFactory.Standard
Annotations
@FunctionalInterface
@API
status:EXPERIMENTAL
since:5.10
Static Imports
org.apiguardian.api.API.Status.EXPERIMENTAL

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 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 @TempDir annotation.

Since
5.10
See Also
@TempDir

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
TempDirFactory.Standard

Standard TempDirFactory implementation which delegates to Files#createTempDirectory using "junit" as the prefix.

Method Summary

Modifier and TypeMethod and Description
public default void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
public Path

Returns:

the path to the newly created temporary directory; never null
createTempDirectory
(AnnotatedElementContext
the context of the field or parameter where @TempDir is declared; never null
elementContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Create a new temporary directory.

Method Detail

closeback to summary
public default void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
createTempDirectoryback to summary
public Path createTempDirectory(AnnotatedElementContext elementContext, ExtensionContext extensionContext) throws Exception

Create a new temporary directory.

Depending on the implementation, the resulting Path may or may not be associated with the default FileSystem.

Parameters
elementContext:AnnotatedElementContext

the context of the field or parameter where @TempDir is declared; never null

extensionContext:ExtensionContext

the current extension context; never null

Returns:Path

the path to the newly created temporary directory; never null

Exceptions
Exception:
in case of failures
org.junit.jupiter.api.io back to summary

public Class TempDirFactory.Standard

extends Object
implements TempDirFactory
Class Inheritance
All Implemented Interfaces
org.junit.jupiter.api.io.TempDirFactory, java.io.Closeable, java.lang.AutoCloseable

Standard TempDirFactory implementation which delegates to Files#createTempDirectory using "junit" as the prefix.
See Also
Files#createTempDirectory(java.lang.String, java.nio.file.attribute.FileAttribute[])

Field Summary

Modifier and TypeField and Description
public static final TempDirFactory
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Path
createTempDirectory(AnnotatedElementContext
the context of the field or parameter where @TempDir is declared; never null
elementContext
,
ExtensionContext
the current extension context; never null
extensionContext
)

Implements org.junit.jupiter.api.io.TempDirFactory.createTempDirectory.

Create a new temporary directory.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
public static final TempDirFactory INSTANCE
TEMP_DIR_PREFIXback to summary
private static final String TEMP_DIR_PREFIX

Constructor Detail

Standardback to summary
public Standard()

Method Detail

createTempDirectoryback to summary
public Path createTempDirectory(AnnotatedElementContext elementContext, ExtensionContext extensionContext) throws IOException

Implements org.junit.jupiter.api.io.TempDirFactory.createTempDirectory.

Doc from org.junit.jupiter.api.io.TempDirFactory.createTempDirectory.

Create a new temporary directory.

Depending on the implementation, the resulting Path may or may not be associated with the default FileSystem.

Parameters
elementContext:AnnotatedElementContext

the context of the field or parameter where @TempDir is declared; never null

extensionContext:ExtensionContext

the current extension context; never null

Returns:Path

the path to the newly created temporary directory; never null

Annotations
@Override