Class TempDirectory
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 TypeClassDescriptionprivate static class
(package private) static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private static final ExtensionContext.Namespace
private static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
assertSupportedType
(String target, Class<?> type) void
beforeAll
(ExtensionContext context) void
beforeEach
(ExtensionContext context) private static TempDirectory.CloseablePath
private Object
getPathOrFile
(AnnotatedElement sourceElement, Class<?> type, 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:
-
TEMP_DIR_PREFIX
- See Also:
-
-
Constructor Details
-
TempDirectory
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:
-
assertSupportedType
-
getPathOrFile
private Object getPathOrFile(AnnotatedElement sourceElement, Class<?> type, ExtensionContext extensionContext) -
getScope
-
createTempDir
-