Class TempDirectory
java.lang.Object
org.junit.jupiter.engine.extension.TempDirectory
- All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeAllCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.ParameterResolver
class TempDirectory
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.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.
- Since:
- 5.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
(package private) static enum
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
assertSupportedType
(String target, Class<?> type) void
beforeAll
(org.junit.jupiter.api.extension.ExtensionContext context) void
beforeEach
(org.junit.jupiter.api.extension.ExtensionContext context) private static TempDirectory.CloseablePath
private Object
getPathOrFile
(AnnotatedElement sourceElement, Class<?> type, org.junit.jupiter.api.extension.ExtensionContext extensionContext) private TempDirectory.Scope
getScope
(org.junit.jupiter.api.extension.ExtensionContext context) private void
injectFields
(org.junit.jupiter.api.extension.ExtensionContext context, Object testInstance, Class<?> testClass, Predicate<Field> predicate) private void
injectInstanceFields
(org.junit.jupiter.api.extension.ExtensionContext context, Object instance) private void
injectStaticFields
(org.junit.jupiter.api.extension.ExtensionContext context, Class<?> testClass) resolveParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) Resolve the current temporary directory for theParameter
in the suppliedParameterContext
.boolean
supportsParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
Field Details
-
NAMESPACE
private static final org.junit.jupiter.api.extension.ExtensionContext.Namespace NAMESPACE -
KEY
- See Also:
-
TEMP_DIR_PREFIX
- See Also:
-
-
Constructor Details
-
TempDirectory
TempDirectory()
-
-
Method Details
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) Perform field injection for non-private,static
fields (i.e., class fields) of typePath
orFile
that are annotated with@TempDir
.- Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) 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 interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-
injectStaticFields
private void injectStaticFields(org.junit.jupiter.api.extension.ExtensionContext context, Class<?> testClass) -
injectInstanceFields
private void injectInstanceFields(org.junit.jupiter.api.extension.ExtensionContext context, Object instance) -
injectFields
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) - Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) Resolve the current temporary directory for theParameter
in the suppliedParameterContext
.- Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
-
assertSupportedType
-
getPathOrFile
private Object getPathOrFile(AnnotatedElement sourceElement, Class<?> type, org.junit.jupiter.api.extension.ExtensionContext extensionContext) -
getScope
-
createTempDir
-