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 asAutoCloseable
and/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 void
close()
static <T extends AutoCloseable>
AutoCloseableResource.Wrapper<T>forAutoCloseable(T closeable)
Creates a wrapper for anAutoCloseable
object.static <T> AutoCloseableResource.Wrapper<T>
forObject(T object, AutoCloseable onClose)
Creates a wrapper for an object.T
unwrap()
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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceExtensionContext.Store.CloseableResource
- Throws:
Exception
-
forAutoCloseable
public static <T extends AutoCloseable> AutoCloseableResource.Wrapper<T> forAutoCloseable(T closeable)
Creates a wrapper for anAutoCloseable
object.This method should not be necessary for JUnit 5.13, as from that version onward
AutoCloseable
can be used withExtensionContext.Store
directly.- 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.
-
-