Top Description Inners Fields Constructors Methods
org.junit.jupiter.engine.extension

pack-priv Class TempDirectory

extends Object
implements BeforeAllCallback, BeforeEachCallback, ParameterResolver
Class Inheritance
All Implemented Interfaces
org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstantiationAwareExtension, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.BeforeAllCallback
Static Imports
java.nio.file.FileVisitResult.CONTINUE, .FileVisitResult.SKIP_SUBTREE, java.util.stream.Collectors.joining, org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope.TEST_METHOD, org.junit.jupiter.api.io.CleanupMode.DEFAULT, .CleanupMode.NEVER, .CleanupMode.ON_SUCCESS, org.junit.platform.commons.support.AnnotationSupport.findAnnotatedFields, .AnnotationSupport.findAnnotation, .ReflectionSupport.makeAccessible, org.junit.platform.commons.util.ReflectionUtils.isRecordObject

TempDirectory is a JUnit Jupiter extension that creates and cleans up temporary directories if a field in a test class or a parameter in a test class constructor, lifecycle method, or test method is annotated with @TempDir.

Consult the Javadoc for TempDir for details on the contract.

Since
5.4
See Also
@TempDir, Files#createTempDirectory

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
TempDirectory.CloseablePath

References Deprecated ExtensionContext.Store.CloseableResource is deprecated or references (maybe indirectly) at least one deprecated element.
private static record
TempDirectory.FailureTracker

References Deprecated ExtensionContext.Store.CloseableResource is deprecated or references (maybe indirectly) at least one deprecated element.
private static record
pack-priv static interface

Field Summary

Modifier and TypeField and Description
private static final String
private final JupiterConfiguration
private static final String
pack-priv static final String
private static final String
pack-priv static final ExtensionContext.Namespace

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static void
private static void
assertSupportedType(String target, Class<?> type)

public void
beforeAll(ExtensionContext context)

Implements org.junit.jupiter.api.extension.BeforeAllCallback.beforeAll.

Perform field injection for non-private, static fields (i.e., class fields) of type Path or File that are annotated with @TempDir.

public void
beforeEach(ExtensionContext context)

Implements org.junit.jupiter.api.extension.BeforeEachCallback.beforeEach.

Perform field injection for non-private, non-static fields (i.e., instance fields) of type Path or File that are annotated with @TempDir.

pack-priv static TempDirectory.CloseablePath
createTempDir(TempDirFactory factory, CleanupMode cleanupMode, Class<?> elementType, AnnotatedElementContext elementContext, ExtensionContext extensionContext)
References Deprecated TempDirectory.CloseablePath is deprecated or references (maybe indirectly) at least one deprecated element.

private CleanupMode
private CleanupMode
private CleanupMode
private TempDirFactory
private TempDirFactory
private TempDirFactory
private static ExtensionContext.Store
private static Object
getPathOrFile(Class<?> elementType, AnnotatedElementContext elementContext, TempDirFactory factory, CleanupMode cleanupMode, ExtensionContext extensionContext)

public TestInstantiationAwareExtension.ExtensionContextScope
getTestInstantiationExtensionContextScope(ExtensionContext rootContext)

Overrides default org.junit.jupiter.api.extension.TestInstantiationAwareExtension.getTestInstantiationExtensionContextScope.

Determine whether this extension should receive a test-method scoped ExtensionContext during the instantiation of test classes or processing of test instances.

private void
injectFields(ExtensionContext context, @Nullable Object testInstance, Class<?> testClass, Predicate<Field> predicate)

private void
private void
injectStaticFields(ExtensionContext context, Class<?> testClass)

private static void
private static void
public Object
resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)

Implements org.junit.jupiter.api.extension.ParameterResolver.resolveParameter.

Resolve the current temporary directory for the Parameter in the supplied ParameterContext.

private static boolean
public boolean
supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)

Implements org.junit.jupiter.api.extension.ParameterResolver.supportsParameter.

Determine if the Parameter in the supplied ParameterContext is annotated with @TempDir.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHILD_FAILEDback to summary
private static final String CHILD_FAILED
configurationback to summary
private final JupiterConfiguration configuration
FAILURE_TRACKERback to summary
private static final String FAILURE_TRACKER
FILE_OPERATIONS_KEYback to summary
pack-priv static final String FILE_OPERATIONS_KEY
KEYback to summary
private static final String KEY
NAMESPACEback to summary
pack-priv static final ExtensionContext.Namespace NAMESPACE

Constructor Detail

TempDirectoryback to summary
pack-priv TempDirectory(JupiterConfiguration configuration)

Method Detail

assertNonFinalFieldback to summary
private static void assertNonFinalField(Field field)
assertSupportedTypeback to summary
private static void assertSupportedType(String target, Class<?> type)
beforeAllback to summary
public void beforeAll(ExtensionContext context)

Implements org.junit.jupiter.api.extension.BeforeAllCallback.beforeAll.

Perform field injection for non-private, static fields (i.e., class fields) of type Path or File that are annotated with @TempDir.

Annotations
@Override
beforeEachback to summary
public void beforeEach(ExtensionContext context)

Implements org.junit.jupiter.api.extension.BeforeEachCallback.beforeEach.

Perform field injection for non-private, non-static fields (i.e., instance fields) of type Path or File that are annotated with @TempDir.

Annotations
@Override
createTempDirback to summary
pack-priv static TempDirectory.CloseablePath createTempDir(TempDirFactory factory, CleanupMode cleanupMode, Class<?> elementType, AnnotatedElementContext elementContext, ExtensionContext extensionContext)

References Deprecated

TempDirectory.CloseablePath is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

determineCleanupModeback to summary
private CleanupMode determineCleanupMode(TempDir tempDir)
determineCleanupModeForFieldback to summary
private CleanupMode determineCleanupModeForField(Field field)
determineCleanupModeForParameterback to summary
private CleanupMode determineCleanupModeForParameter(ParameterContext parameterContext)
determineTempDirFactoryback to summary
private TempDirFactory determineTempDirFactory(TempDir tempDir)
determineTempDirFactoryForFieldback to summary
private TempDirFactory determineTempDirFactoryForField(Field field)
determineTempDirFactoryForParameterback to summary
private TempDirFactory determineTempDirFactoryForParameter(ParameterContext parameterContext)
getContextSpecificStoreback to summary
private static ExtensionContext.Store getContextSpecificStore(ExtensionContext context)
getPathOrFileback to summary
private static Object getPathOrFile(Class<?> elementType, AnnotatedElementContext elementContext, TempDirFactory factory, CleanupMode cleanupMode, ExtensionContext extensionContext)
getTestInstantiationExtensionContextScopeback to summary
public TestInstantiationAwareExtension.ExtensionContextScope getTestInstantiationExtensionContextScope(ExtensionContext rootContext)

Overrides default org.junit.jupiter.api.extension.TestInstantiationAwareExtension.getTestInstantiationExtensionContextScope.

Doc from org.junit.jupiter.api.extension.TestInstantiationAwareExtension.getTestInstantiationExtensionContextScope.

Determine whether this extension should receive a test-method scoped ExtensionContext during the instantiation of test classes or processing of test instances.

If an extension returns TEST_METHOD from this method, methods defined in the following extension APIs will be called with a test-method scoped ExtensionContext instead of a test-class scoped context. Note, however, that a test-class scoped context will always be supplied if the PER_CLASS test instance lifecycle is used.

When a test-method scoped ExtensionContext is supplied, implementations of the above extension APIs will observe the following differences.

Note

The behavior which is enabled by returning TEST_METHOD from this method will become the default in future versions of JUnit. To ensure forward compatibility, extension authors are therefore advised to opt into this feature, even if they do not require the new functionality.

Annotations
@Override
injectFieldsback to summary
private void injectFields(ExtensionContext context, @Nullable Object testInstance, Class<?> testClass, Predicate<Field> predicate)
injectInstanceFieldsback to summary
private void injectInstanceFields(ExtensionContext context, Object instance)
injectStaticFieldsback to summary
private void injectStaticFields(ExtensionContext context, Class<?> testClass)
installFailureTrackerback to summary
private static void installFailureTracker(ExtensionContext context)
installFailureTrackerback to summary
private static void installFailureTracker(ExtensionContext context, ExtensionContext parentContext)
resolveParameterback to summary
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)

Implements org.junit.jupiter.api.extension.ParameterResolver.resolveParameter.

Resolve the current temporary directory for the Parameter in the supplied ParameterContext.

Annotations
@Override
selfOrChildFailedback to summary
private static boolean selfOrChildFailed(ExtensionContext context)
supportsParameterback to summary
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)

Implements org.junit.jupiter.api.extension.ParameterResolver.supportsParameter.

Determine if the Parameter in the supplied ParameterContext is annotated with @TempDir.

Annotations
@Override
org.junit.jupiter.engine.extension back to summary

pack-priv Class TempDirectory.CloseablePath

extends Object
implements CloseableResource, AutoCloseable
Class Inheritance
  • java.lang.Object
  • org.junit.jupiter.engine.extension.TempDirectory.CloseablePath
All Implemented Interfaces
java.lang.AutoCloseable, org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource
Annotations
@SuppressWarnings:deprecation

References Deprecated

ExtensionContext.Store.CloseableResource is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Field Summary

Modifier and TypeField and Description
private final AnnotatedElement
private final CleanupMode
private final Path
private final ExtensionContext
private final TempDirFactory
private static final Logger

Constructor Summary

AccessConstructor and Description
private
CloseablePath(TempDirFactory factory, CleanupMode cleanupMode, Class<?> elementType, AnnotatedElementContext elementContext, ExtensionContext extensionContext)

Method Summary

Modifier and TypeMethod and Description
public void
private IOException
private SortedMap<Path, IOException>
private static String
descriptionFor(AnnotatedElement annotatedElement)

private static String
pack-priv Path
get()

private Path
private Path
private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotatedElementback to summary
private final AnnotatedElement annotatedElement
cleanupModeback to summary
private final CleanupMode cleanupMode
dirback to summary
private final Path dir
extensionContextback to summary
private final ExtensionContext extensionContext
factoryback to summary
private final TempDirFactory factory
LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

CloseablePathback to summary
private CloseablePath(TempDirFactory factory, CleanupMode cleanupMode, Class<?> elementType, AnnotatedElementContext elementContext, ExtensionContext extensionContext) throws Exception

Method Detail

closeback to summary
public void close() throws IOException

Implements org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource.close, java.lang.AutoCloseable.close.

Doc from org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource.close.

Close underlying resources.

Annotations
@Override
createIOExceptionWithAttachedFailuresback to summary
private IOException createIOExceptionWithAttachedFailures(SortedMap<Path, IOException> failures)
deleteAllFilesAndDirectoriesback to summary
private SortedMap<Path, IOException> deleteAllFilesAndDirectories(TempDirectory.FileOperations fileOperations) throws IOException
descriptionForback to summary
private static String descriptionFor(AnnotatedElement annotatedElement)
Since
5.12
descriptionForback to summary
private static String descriptionFor(Executable executable)
Since
5.12
getback to summary
pack-priv Path get()
relativizeSafelyback to summary
private Path relativizeSafely(Path path)
tryToDeleteOnExitback to summary
private Path tryToDeleteOnExit(Path path)
Annotations
@SuppressWarnings:EmptyCatch
tryToResetPermissionsback to summary
private static void tryToResetPermissions(Path path)
Annotations
@SuppressWarnings:ResultOfMethodCallIgnored
org.junit.jupiter.engine.extension back to summary

private final Record TempDirectory.FailureTracker

extends Record
implements CloseableResource, AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable, org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource
Annotations
@SuppressWarnings:deprecation
Record Components
context:ExtensionContext 
parentContext:ExtensionContext 

References Deprecated

ExtensionContext.Store.CloseableResource is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Field Summary

Modifier and TypeField and Description
private final ExtensionContext
context

Record Component accessed by context().

private final ExtensionContext
parentContext

Record Component accessed by parentContext().

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public ExtensionContext
context()

Record Component getter of context.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public ExtensionContext
parentContext()

Record Component getter of parentContext.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

contextback to summary
private final ExtensionContext context

Record Component accessed by context().

parentContextback to summary
private final ExtensionContext parentContext

Record Component accessed by parentContext().

Constructor Detail

FailureTrackerback to summary
private FailureTracker(ExtensionContext context, ExtensionContext parentContext)

Method Detail

closeback to summary
public void close()

Implements org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource.close, java.lang.AutoCloseable.close.

Doc from org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource.close.

Close underlying resources.

Annotations
@Override
contextback to summary
public ExtensionContext context()

Record Component getter of context.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

parentContextback to summary
public ExtensionContext parentContext()

Record Component getter of parentContext.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

org.junit.jupiter.engine.extension back to summary

private final Record TempDirectory.FieldContext

extends Record
implements AnnotatedElementContext
Class Inheritance
All Implemented Interfaces
org.junit.jupiter.api.extension.AnnotatedElementContext
Record Components
field:Field 

Field Summary

Modifier and TypeField and Description
private final Field
field

Record Component accessed by field().

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public Field
field()

Record Component getter of field.

public AnnotatedElement
public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

fieldback to summary
private final Field field

Record Component accessed by field().

Constructor Detail

FieldContextback to summary
private FieldContext(Field field)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
fieldback to summary
public Field field()

Record Component getter of field.

getAnnotatedElementback to summary
public AnnotatedElement getAnnotatedElement()

Implements org.junit.jupiter.api.extension.AnnotatedElementContext.getAnnotatedElement.

Doc from org.junit.jupiter.api.extension.AnnotatedElementContext.getAnnotatedElement.

Get the AnnotatedElement for this context.

WARNING

When searching for annotations on the annotated element in this context, favor isAnnotated(Class), findAnnotation(Class), and findRepeatableAnnotations(Class) over methods in the AnnotatedElement API due to a bug in javac on JDK versions prior to JDK 9.

Annotations
@Override
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

toStringback to summary
public String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Annotations
@Override
org.junit.jupiter.engine.extension back to summary

pack-priv Interface TempDirectory.FileOperations


Field Summary

Modifier and TypeField and Description
public static final TempDirectory.FileOperations

Method Summary

Modifier and TypeMethod and Description
public void
delete(Path path)

Field Detail

DEFAULTback to summary
public static final TempDirectory.FileOperations DEFAULT

Method Detail

deleteback to summary
public void delete(Path path) throws IOException