Interface TempDirDeletionStrategy
- All Known Implementing Classes:
TempDirDeletionStrategy.IgnoreFailures, TempDirDeletionStrategy.Standard
@API(status=EXPERIMENTAL,
since="6.1")
public interface TempDirDeletionStrategy
TempDirDeletionStrategy defines the SPI for deleting temporary
directories programmatically.
A deletion strategy controls how a temporary directory is cleaned up when the end of its scope is reached.
Implementations must provide a no-args constructor.
A TempDirDeletionStrategy can be configured globally
for the entire test suite via the
"junit.jupiter.tempdir.deletion.strategy.default" configuration
parameter (see the User Guide for details) or locally for a test
class field or method parameter via the @TempDir annotation.
- Since:
- 6.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final classException thrown when one or more paths in a temporary directory could not be deleted by aTempDirDeletionStrategy.static interfaceRepresents a single failure that occurred while attempting to delete a path during adelete(Path, AnnotatedElementContext, ExtensionContext)operation.static interfaceRepresents the result of adelete(Path, AnnotatedElementContext, ExtensionContext)operation, including any paths that could not be deleted.static final classATempDirDeletionStrategythat delegates toTempDirDeletionStrategy.Standardbut suppresses deletion failures by logging a warning instead of propagating them.static final classStandardTempDirDeletionStrategyimplementation that recursively deletes all files and directories within the temporary directory. -
Method Summary
Modifier and TypeMethodDescriptiondelete(Path tempDir, AnnotatedElementContext elementContext, ExtensionContext extensionContext) Delete the supplied temporary directory and all of its contents.
-
Method Details
-
delete
TempDirDeletionStrategy.DeletionResult delete(Path tempDir, AnnotatedElementContext elementContext, ExtensionContext extensionContext) throws IOException Delete the supplied temporary directory and all of its contents.Depending on the used
TempDirFactory, the suppliedPathmay or may not be associated with the default FileSystem.- Parameters:
tempDir- the temporary directory to delete; nevernullelementContext- the context of the field or parameter where@TempDiris declared; nevernullextensionContext- the current extension context; nevernull- Returns:
- a
TempDirDeletionStrategy.DeletionResult, potentially containing failures forPathsthat could not be deleted or no failures if deletion was successful; nevernull - Throws:
IOException- in case of general failures
-