Top Description Methods
org.junit.jupiter.params.converter

public Interface ArgumentConverter

Known Direct Implementers
org.junit.jupiter.params.converter.DefaultArgumentConverter, org.junit.jupiter.params.converter.SimpleArgumentConverter, org.junit.jupiter.params.converter.TypedArgumentConverter, org.junit.jupiter.params.converter.AnnotationBasedArgumentConverter
Annotations
@API
status:STABLE
since:5.7
Static Imports
org.apiguardian.api.API.Status.EXPERIMENTAL, .API.Status.STABLE

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 or a constructor parameter or @Parameter-annotated field of a @ParameterizedClass with the help of a @ConvertWith annotation.

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 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.

Since
5.0
See Also
org.junit.jupiter.params.ParameterizedTest, org.junit.jupiter.params.converter.ConvertWith, org.junit.jupiter.params.support.AnnotationConsumer, SimpleArgumentConverter, TypedArgumentConverter

Method Summary

Modifier and TypeMethod and Description
public @Nullable Object

Returns:

the converted object; may be null but only if the target type is a reference type
convert
(@Nullable Object
the source object to convert; may be null
source
,
ParameterContext
the parameter context where the converted object will be supplied; never null
context
)

Convert the supplied source object according to the supplied context.

public default @Nullable Object

Returns:

the converted object; may be null but only if the target type is a reference type
convert
(@Nullable Object
the source object to convert; may be null
source
,
FieldContext
the field context where the converted object will be injected; never null
context
)

Convert the supplied source object according to the supplied context.

Method Detail

convertback to summary
public @Nullable Object convert(@Nullable Object source, ParameterContext context) throws ArgumentConversionException

Convert the supplied source object according to the supplied context.

Parameters
source:@Nullable Object

the source object to convert; may be null

context:ParameterContext

the parameter context where the converted object will be supplied; never null

Returns:@Nullable Object

the converted object; may be null but only if the target type is a reference type

Exceptions
ArgumentConversionException:
if an error occurs during the conversion
convertback to summary
public default @Nullable Object convert(@Nullable Object source, FieldContext context) throws ArgumentConversionException

Convert the supplied source object according to the supplied context.

Parameters
source:@Nullable Object

the source object to convert; may be null

context:FieldContext

the field context where the converted object will be injected; never null

Returns:@Nullable Object

the converted object; may be null but only if the target type is a reference type

Annotations
@API
status:EXPERIMENTAL
since:6.0
Exceptions
ArgumentConversionException:
if an error occurs during the conversion
Since
5.13