Class TypedArgumentConverter<S,T>
- java.lang.Object
-
- org.junit.jupiter.params.converter.TypedArgumentConverter<S,T>
-
- Type Parameters:
S- the type of the source argument to convertT- the type of the target object to create from the source
- All Implemented Interfaces:
ArgumentConverter
@API(status=STABLE, since="5.10") public abstract class TypedArgumentConverter<S,T> extends java.lang.Object implements ArgumentConverterTypedArgumentConverteris an abstract base class forArgumentConverterimplementations that always convert objects of a given source type into a given target type.- Since:
- 5.7
- See Also:
ArgumentConverter,SimpleArgumentConverter
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<S>sourceTypeprivate java.lang.Class<T>targetType
-
Constructor Summary
Constructors Modifier Constructor Description protectedTypedArgumentConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)Create a newTypedArgumentConverter.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private Tconvert(java.lang.Object source, java.lang.Class<?> actualTargetType)java.lang.Objectconvert(java.lang.Object source, org.junit.jupiter.api.extension.ParameterContext context)Convert the suppliedsourceobject according to the suppliedcontext.java.lang.Objectconvert(java.lang.Object source, FieldContext context)Convert the suppliedsourceobject according to the suppliedcontext.protected abstract Tconvert(S source)Convert the suppliedsourceobject of typeSinto an object of typeT.
-
-
-
Constructor Detail
-
TypedArgumentConverter
protected TypedArgumentConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)
Create a newTypedArgumentConverter.- Parameters:
sourceType- the type of the argument to convert; nevernulltargetType- the type of the target object to create from the source; nevernull
-
-
Method Detail
-
convert
public final java.lang.Object convert(java.lang.Object source, org.junit.jupiter.api.extension.ParameterContext context) throws ArgumentConversionExceptionDescription copied from interface:ArgumentConverterConvert the suppliedsourceobject according to the suppliedcontext.- Specified by:
convertin interfaceArgumentConverter- 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
public final java.lang.Object convert(java.lang.Object source, FieldContext context) throws ArgumentConversionExceptionDescription copied from interface:ArgumentConverterConvert the suppliedsourceobject according to the suppliedcontext.- Specified by:
convertin interfaceArgumentConverter- 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
-
convert
private T convert(java.lang.Object source, java.lang.Class<?> actualTargetType)
-
convert
protected abstract T convert(S source) throws ArgumentConversionException
Convert the suppliedsourceobject of typeSinto an object of typeT.- Parameters:
source- the source object to convert; may benull- 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
-
-