Annotation Type LoadWith
-
@Target({FIELD,PARAMETER,ANNOTATION_TYPE}) @Retention(RUNTIME) public @interface LoadWith
LoadWith
can be used in combination withTestResource
to specify a factory method to load the contents of a resource into an object.By default, any
AutoCloseable
orExtensionContext.Store.CloseableResource
return value of the factory method is automatically closed once it goes out of scope. To turn this off forAutoCloseable
, set the "com.github.robtimus.junit.support.extension.testresource.closeAutoCloseable" configuration parameter tofalse
. This can be done via the JUnitLauncher
API, build tools (e.g., Gradle and Maven), a JVM system property, or the JUnit Platform configuration file (i.e., a file namedjunit-platform.properties
in the root of the class path). Consult the JUnit User Guide for further information.- Author:
- Rob Spoor
- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Fields Description static String
CLOSE_AUTO_CLOSEABLE
The property that can be used to enable or disable automatically closingAutoCloseable
return values of factory methods.
-
-
-
Field Detail
-
CLOSE_AUTO_CLOSEABLE
static final String CLOSE_AUTO_CLOSEABLE
The property that can be used to enable or disable automatically closingAutoCloseable
return values of factory methods.- Since:
- 3.1
-
-
Element Detail
-
value
String value
The name of the factory method within the test class or in an external class to use to load the contents of the resource into an object. The method must take a singleInputStream
orReader
argument, and an optionalInjectionTarget
orClass
argument that represents the injection target or the target type respectively.If no arguments are specified in the factory method name, the following parameter types are tried:
Reader
andInjectionTarget
Reader
andClass
Reader
InputStream
andInjectionTarget
InputStream
andClass
InputStream
A factory method within the test class must be static when used for static field or constructor parameter injection. It may be non-static when used for instance field or method parameter injection.
A factory method in an external class must always be static, and must be referenced by fully qualified method name.
Examples:
loadResource
for a method in the test class; the same asloadResource(java.io.Reader, com.github.robtimus.junit.support.extension.InjectionTarget)
if it exists, otherwiseloadResource(java.io.Reader, java.lang.Class)
if it exists, otherwiseloadResource(java.io.Reader)
if it exists, otherwiseloadResource(java.io.InputStream, com.github.robtimus.junit.support.extension.InjectionTarget)
if it exists, otherwiseloadResource(java.io.InputStream, java.lang.Class)
if it exists, otherwiseloadResource(java.io.InputStream)
loadResource(java.io.Reader, com.github.robtimus.junit.support.extension.InjectionTarget)
for a method in the test class that takesReader
andInjectionTarget
argumentsloadResource(java.io.Reader, java.lang.Class)
for a method in the test class that takesReader
andClass
argumentsloadResource(java.io.Reader)
for a method in the test class that takes a singleReader
argumentloadResource(java.io.InputStream)
for a method in the test class that takes a singleReader
argumentcom.github.robtimus.junit.support.extension.testresource.TestResourceLoaders#toString(java.io.Reader)
for a method in an external class that takes a singleReader
classcom.github.robtimus.junit.support.extension.testresource.TestResourceLoaders#toBytes(java.io.InputStream)
for a method in an external class that takes a singleInputStream
class
-
-