Class AutoCloseableResource.Wrapper<T>
- java.lang.Object
-
- com.github.robtimus.junit.support.extension.AutoCloseableResource.Wrapper<T>
-
- Type Parameters:
T- The type of the wrapped object.
- All Implemented Interfaces:
AutoCloseableResource,AutoCloseable,ExtensionContext.Store.CloseableResource
- Enclosing interface:
- AutoCloseableResource
public static final class AutoCloseableResource.Wrapper<T> extends Object implements AutoCloseableResource
A wrapper that allows any object type to be used asAutoCloseableand/orExtensionContext.Store.CloseableResource.- Author:
- Rob Spoor
- Since:
- 3.1
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.github.robtimus.junit.support.extension.AutoCloseableResource
AutoCloseableResource.Wrapper<T>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static <T extends AutoCloseable>
AutoCloseableResource.Wrapper<T>forAutoCloseable(T closeable)Creates a wrapper for anAutoCloseableobject.static <T> AutoCloseableResource.Wrapper<T>forObject(T object, AutoCloseable onClose)Creates a wrapper for an object.Tunwrap()Returns the wrapped object.
-
-
-
Method Detail
-
unwrap
public T unwrap()
Returns the wrapped object.- Returns:
- The wrapped object.
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceExtensionContext.Store.CloseableResource- Throws:
Exception
-
forAutoCloseable
public static <T extends AutoCloseable> AutoCloseableResource.Wrapper<T> forAutoCloseable(T closeable)
Creates a wrapper for anAutoCloseableobject.This method should not be necessary for JUnit 5.13, as from that version onward
AutoCloseablecan be used withExtensionContext.Storedirectly.- Type Parameters:
T- The object type.- Parameters:
closeable- The object to create a wrapper for.- Returns:
- A wrapper for the given object.
-
forObject
public static <T> AutoCloseableResource.Wrapper<T> forObject(T object, AutoCloseable onClose)
Creates a wrapper for an object.- Type Parameters:
T- The object type.- Parameters:
object- The object to create a wrapper for.onClose- An action to execute when the wrapper is closed, as anAutoCloseable. It will be called at most once.- Returns:
- A wrapper for the given object.
-
-