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.- Author:
- Rob Spoor
- Since:
- 2.0
-
-
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
-
-