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 TypeClassDescription(package private) static class(package private) static interface(package private) static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JupiterConfiguration(package private) static final Stringprivate static final String(package private) static final ExtensionContext.Namespaceprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidassertNonFinalField(Field field) private voidassertSupportedType(String target, Class<?> type) voidbeforeAll(ExtensionContext context) voidbeforeEach(ExtensionContext context) (package private) static TempDirectory.CloseablePathcreateTempDir(CleanupMode cleanupMode, ExtensionContext executionContext) private CleanupModedetermineCleanupMode(TempDir tempDir) private CleanupModeprivate CleanupModedetermineCleanupModeForParameter(ParameterContext parameterContext) private ObjectgetPathOrFile(AnnotatedElement sourceElement, Class<?> type, CleanupMode cleanupMode, ExtensionContext extensionContext) private TempDirectory.ScopegetScope(ExtensionContext context) 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:
-
FILE_OPERATIONS_KEY
- See Also:
-
configuration
-
-
Constructor Details
-
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) -
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:
-
determineCleanupModeForField
-
determineCleanupModeForParameter
-
determineCleanupMode
-
assertNonFinalField
-
assertSupportedType
-
getPathOrFile
private Object getPathOrFile(AnnotatedElement sourceElement, Class<?> type, CleanupMode cleanupMode, ExtensionContext extensionContext) -
getScope
-
createTempDir
static TempDirectory.CloseablePath createTempDir(CleanupMode cleanupMode, ExtensionContext executionContext)
-