@API(status=STABLE,
since="5.7")
public interface ArgumentConverter
ArgumentConverter is an abstraction that allows an input object to
be converted to an instance of a different class.
Such an ArgumentConverter is applied to the method parameter
of a @ParameterizedTest
method with the help of a
@ConvertWith annotation.
Implementations must provide a no-args constructor and should not make any assumptions regarding when they are instantiated or how often they are called. Since instances may potentially be cached and called from different threads, they should be thread-safe and designed to be used as singletons.
Extend SimpleArgumentConverter if your implementation only needs
to know the target type and does not need access to the ParameterContext
to perform the conversion.
Extend TypedArgumentConverter if your implementation always converts
from a given source type into a given target type and does not need access to
the ParameterContext to perform the conversion.
SimpleArgumentConverter,
ParameterizedTest,
ConvertWith,
AnnotationConsumer,
SimpleArgumentConverter,
TypedArgumentConverter| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
convert(java.lang.Object source,
ParameterContext context)
Convert the supplied
source object according to the supplied
context. |
java.lang.Object convert(java.lang.Object source,
ParameterContext context)
throws ArgumentConversionException
source object according to the supplied
context.source - the source object to convert; may be nullcontext - the parameter context where the converted object will be
used; never nullnull but only if the target
type is a reference typeArgumentConversionException - if an error occurs during the
conversion