java.lang.Object
org.junit.jupiter.engine.extension.TempDirectory
- All Implemented Interfaces:
BeforeAllCallback
,BeforeEachCallback
,Extension
,ParameterResolver
class TempDirectory
extends Object
implements BeforeAllCallback, BeforeEachCallback, ParameterResolver
TempDirectory
is a JUnit Jupiter extension that creates and cleans
up temporary directories if field in a test class or a parameter in a
lifecycle method or test method is annotated with @TempDir
.
Consult the Javadoc for TempDir
for details on the contract.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
private static class
(package private) static interface
(package private) static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JupiterConfiguration
(package private) static final String
private static final String
(package private) static final ExtensionContext.Namespace
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
assertNonFinalField
(Field field) private void
assertSupportedType
(String target, Class<?> type) void
beforeAll
(ExtensionContext context) void
beforeEach
(ExtensionContext context) (package private) static TempDirectory.CloseablePath
createTempDir
(TempDirFactory factory, CleanupMode cleanupMode, AnnotatedElementContext elementContext, ExtensionContext extensionContext) private CleanupMode
determineCleanupMode
(TempDir tempDir) private CleanupMode
private CleanupMode
determineCleanupModeForParameter
(ParameterContext parameterContext) private TempDirFactory
determineTempDirFactory
(TempDir tempDir, TempDirectory.Scope scope) private TempDirFactory
determineTempDirFactoryForField
(Field field, TempDirectory.Scope scope) private TempDirFactory
determineTempDirFactoryForParameter
(ParameterContext parameterContext, TempDirectory.Scope scope) private Object
getPathOrFile
(AnnotatedElementContext elementContext, Class<?> type, TempDirFactory factory, CleanupMode cleanupMode, TempDirectory.Scope scope, ExtensionContext extensionContext) private TempDirectory.Scope
getScope
(ExtensionContext context) private void
injectFields
(ExtensionContext context, Object testInstance, Class<?> testClass, Predicate<Field> predicate) private void
injectInstanceFields
(ExtensionContext context, Object instance) private void
injectStaticFields
(ExtensionContext context, Class<?> testClass) resolveParameter
(ParameterContext parameterContext, ExtensionContext extensionContext) Resolve the current temporary directory for theParameter
in the suppliedParameterContext
.boolean
supportsParameter
(ParameterContext parameterContext, ExtensionContext extensionContext)
-
Field Details
-
NAMESPACE
-
KEY
- See Also:
-
FILE_OPERATIONS_KEY
- See Also:
-
configuration
-
-
Constructor Details
-
TempDirectory
-
-
Method Details
-
beforeAll
Perform field injection for non-private,static
fields (i.e., class fields) of typePath
orFile
that are annotated with@TempDir
.- Specified by:
beforeAll
in interfaceBeforeAllCallback
- Parameters:
context
- the current extension context; nevernull
-
beforeEach
Perform field injection for non-private, non-static fields (i.e., instance fields) of typePath
orFile
that are annotated with@TempDir
.- Specified by:
beforeEach
in interfaceBeforeEachCallback
- Parameters:
context
- the current extension context; nevernull
-
injectStaticFields
-
injectInstanceFields
-
injectFields
private void injectFields(ExtensionContext context, Object testInstance, Class<?> testClass, Predicate<Field> predicate) -
supportsParameter
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - Specified by:
supportsParameter
in interfaceParameterResolver
- Parameters:
parameterContext
- the context for the parameter for which an argument should be resolved; nevernull
extensionContext
- the extension context for theExecutable
about to be invoked; nevernull
- Returns:
true
if this resolver can resolve an argument for the parameter- See Also:
-
resolveParameter
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) Resolve the current temporary directory for theParameter
in the suppliedParameterContext
.- Specified by:
resolveParameter
in interfaceParameterResolver
- Parameters:
parameterContext
- the context for the parameter for which an argument should be resolved; nevernull
extensionContext
- the extension context for theExecutable
about to be invoked; nevernull
- Returns:
- the resolved argument for the parameter; may only be
null
if the parameter type is not a primitive - See Also:
-
determineCleanupModeForField
-
determineCleanupModeForParameter
-
determineCleanupMode
-
getScope
-
determineTempDirFactoryForField
-
determineTempDirFactoryForParameter
private TempDirFactory determineTempDirFactoryForParameter(ParameterContext parameterContext, TempDirectory.Scope scope) -
determineTempDirFactory
-
assertNonFinalField
-
assertSupportedType
-
getPathOrFile
private Object getPathOrFile(AnnotatedElementContext elementContext, Class<?> type, TempDirFactory factory, CleanupMode cleanupMode, TempDirectory.Scope scope, ExtensionContext extensionContext) -
createTempDir
static TempDirectory.CloseablePath createTempDir(TempDirFactory factory, CleanupMode cleanupMode, AnnotatedElementContext elementContext, ExtensionContext extensionContext)
-