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

pack-priv Class AutoCloseExtension

extends Object
implements TestInstancePreDestroyCallback, AfterAllCallback
Class Inheritance
All Implemented Interfaces
org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.TestInstancePreDestroyCallback
Static Imports
org.junit.platform.commons.support.HierarchyTraversalMode.BOTTOM_UP

AutoCloseExtension is a JUnit Jupiter extension that closes resources if a field in a test class is annotated with @AutoClose.

Consult the Javadoc for @AutoClose for details on the contract.

Since
5.11
See Also
AutoClose

Field Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

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

Implements org.junit.jupiter.api.extension.AfterAllCallback.afterAll.

Callback that is invoked once after all tests in the current container.

private static void
checkCondition(boolean condition, String messageFormat, Field field)

private static void
closeField(Field field, @Nullable Object testInstance)

private static void
closeFields(Class<?> testClass, @Nullable Object testInstance, ThrowableCollector throwableCollector)

private static String
private static void
invokeCloseMethod(Field field, Object target, String methodName)

public void
preDestroyTestInstance(ExtensionContext context)

Implements org.junit.jupiter.api.extension.TestInstancePreDestroyCallback.preDestroyTestInstance.

Callback for processing test instances before they are destroyed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
private static final Logger logger

Constructor Detail

AutoCloseExtensionback to summary
pack-priv AutoCloseExtension()

Method Detail

afterAllback to summary
public void afterAll(ExtensionContext context)

Implements org.junit.jupiter.api.extension.AfterAllCallback.afterAll.

Doc from org.junit.jupiter.api.extension.AfterAllCallback.afterAll.

Callback that is invoked once after all tests in the current container.

Annotations
@Override
checkConditionback to summary
private static void checkCondition(boolean condition, String messageFormat, Field field)
closeFieldback to summary
private static void closeField(Field field, @Nullable Object testInstance) throws Exception
closeFieldsback to summary
private static void closeFields(Class<?> testClass, @Nullable Object testInstance, ThrowableCollector throwableCollector)
getQualifiedNameback to summary
private static String getQualifiedName(Field field)
invokeCloseMethodback to summary
private static void invokeCloseMethod(Field field, Object target, String methodName) throws Exception
preDestroyTestInstanceback to summary
public void preDestroyTestInstance(ExtensionContext context)

Implements org.junit.jupiter.api.extension.TestInstancePreDestroyCallback.preDestroyTestInstance.

Doc from org.junit.jupiter.api.extension.TestInstancePreDestroyCallback.preDestroyTestInstance.

Callback for processing test instances before they are destroyed.

Contrary to TestInstancePostProcessor#postProcessTestInstance this method is only called once for each ExtensionContext even if there are multiple test instances about to be destroyed in case of @Nested tests. Please use the provided preDestroyTestInstances(ExtensionContext, Consumer) utility method to ensure that all test instances are handled.

Annotations
@Override