Interface ArgumentConverter
-
- All Known Implementing Classes:
AnnotationBasedArgumentConverter,DefaultArgumentConverter,JavaTimeArgumentConverter,SimpleArgumentConverter,TypedArgumentConverter
@API(status=STABLE, since="5.7") public interface ArgumentConverterArgumentConverteris an abstraction that allows an input object to be converted to an instance of a different class.Such an
ArgumentConverteris applied to the method parameter of a@ParameterizedTestor a constructor parameter or@Parameter-annotated field of a@ParameterizedClasswith the help of a@ConvertWithannotation.Implementations must provide a no-args constructor or a single unambiguous constructor to use parameter resolution. They 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.
Extend
SimpleArgumentConverterif your implementation only needs to know the target type and does not need access to theParameterContextto perform the conversion.Extend
TypedArgumentConverterif your implementation always converts from a given source type into a given target type and does not need access to theParameterContextto perform the conversion.- Since:
- 5.0
- See Also:
ParameterizedTest,ConvertWith,AnnotationConsumer,SimpleArgumentConverter,TypedArgumentConverter
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.lang.Objectconvert(java.lang.Object source, org.junit.jupiter.api.extension.ParameterContext context)Convert the suppliedsourceobject according to the suppliedcontext.default java.lang.Objectconvert(java.lang.Object source, FieldContext context)Convert the suppliedsourceobject according to the suppliedcontext.
-
-
-
Method Detail
-
convert
java.lang.Object convert(java.lang.Object source, org.junit.jupiter.api.extension.ParameterContext context) throws ArgumentConversionExceptionConvert the suppliedsourceobject according to the suppliedcontext.- Parameters:
source- the source object to convert; may benullcontext- the parameter context where the converted object will be supplied; nevernull- Returns:
- the converted object; may be
nullbut only if the target type is a reference type - Throws:
ArgumentConversionException- if an error occurs during the conversion
-
convert
@API(status=MAINTAINED, since="5.13.3") default java.lang.Object convert(java.lang.Object source, FieldContext context) throws ArgumentConversionExceptionConvert the suppliedsourceobject according to the suppliedcontext.- Parameters:
source- the source object to convert; may benullcontext- the field context where the converted object will be injected; nevernull- Returns:
- the converted object; may be
nullbut only if the target type is a reference type - Throws:
ArgumentConversionException- if an error occurs during the conversion- Since:
- 5.13
-
-