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.
- Since:
- 5.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final ExtensionContext.Namespaceprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidassertSupportedType(String target, Class<?> type) private voidassertValidFieldCandidate(Field field) voidbeforeAll(ExtensionContext context) voidbeforeEach(ExtensionContext context) private static TempDirectory.CloseablePathprivate ObjectgetPathOrFile(Class<?> type, ExtensionContext extensionContext) private voidinjectFields(ExtensionContext context, Object testInstance, Class<?> testClass, Predicate<Field> predicate) private voidinjectInstanceFields(ExtensionContext context, Object instance) private voidinjectStaticFields(ExtensionContext context, Class<?> testClass) resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) Resolve the current temporary directory for theParameterin the suppliedParameterContext.booleansupportsParameter(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,staticfields (i.e., class fields) of typePathorFilethat are annotated with@TempDir.- Specified by:
beforeAllin interfaceBeforeAllCallback- Parameters:
context- the current extension context; nevernull
-
beforeEach
Perform field injection for non-private, non-static fields (i.e., instance fields) of typePathorFilethat are annotated with@TempDir.- Specified by:
beforeEachin interfaceBeforeEachCallback- Parameters:
context- the current extension context; nevernull
-
injectStaticFields
-
injectInstanceFields
-
injectFields
private void injectFields(ExtensionContext context, Object testInstance, Class<?> testClass, Predicate<Field> predicate) -
assertValidFieldCandidate
-
supportsParameter
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) - Specified by:
supportsParameterin interfaceParameterResolver- Parameters:
parameterContext- the context for the parameter for which an argument should be resolved; nevernullextensionContext- the extension context for theExecutableabout to be invoked; nevernull- Returns:
trueif 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 theParameterin the suppliedParameterContext.- Specified by:
resolveParameterin interfaceParameterResolver- Parameters:
parameterContext- the context for the parameter for which an argument should be resolved; nevernullextensionContext- the extension context for theExecutableabout to be invoked; nevernull- Returns:
- the resolved argument for the parameter; may only be
nullif the parameter type is not a primitive - See Also:
-
assertSupportedType
-
getPathOrFile
-
createTempDir
-