Annotation Type LoadWith
-
@Target({FIELD,PARAMETER,ANNOTATION_TYPE}) @Retention(RUNTIME) public @interface LoadWith
LoadWithcan be used in combination withTestResourceto specify a factory method to load the contents of a resource into an object.By default, any
AutoCloseableorExtensionContext.Store.CloseableResourcereturn 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 JUnitLauncherAPI, build tools (e.g., Gradle and Maven), a JVM system property, or the JUnit Platform configuration file (i.e., a file namedjunit-platform.propertiesin 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 StringCLOSE_AUTO_CLOSEABLEThe property that can be used to enable or disable automatically closingAutoCloseablereturn 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 closingAutoCloseablereturn 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 singleInputStreamorReaderargument, and an optionalInjectionTargetorClassargument 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:
ReaderandInjectionTargetReaderandClassReaderInputStreamandInjectionTargetInputStreamandClassInputStream
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:
loadResourcefor 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 takesReaderandInjectionTargetargumentsloadResource(java.io.Reader, java.lang.Class)for a method in the test class that takesReaderandClassargumentsloadResource(java.io.Reader)for a method in the test class that takes a singleReaderargumentloadResource(java.io.InputStream)for a method in the test class that takes a singleReaderargumentcom.github.robtimus.junit.support.extension.testresource.TestResourceLoaders#toString(java.io.Reader)for a method in an external class that takes a singleReaderclasscom.github.robtimus.junit.support.extension.testresource.TestResourceLoaders#toBytes(java.io.InputStream)for a method in an external class that takes a singleInputStreamclass
-
-