Interface ArgumentConverter

  • All Known Implementing Classes:
    DefaultArgumentConverter, SimpleArgumentConverter

    @API(status=EXPERIMENTAL,
         since="5.0")
    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.

    See SimpleArgumentConverter in case your implementation only needs to know about the target type instead of the complete ParameterContext.

    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.

    Since:
    5.0
    See Also:
    SimpleArgumentConverter, ParameterizedTest, ConvertWith, AnnotationConsumer
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.Object convert​(java.lang.Object source, org.junit.jupiter.api.extension.ParameterContext context)
      Convert the supplied source object according to the supplied context.
    • Method Detail

      • convert

        java.lang.Object convert​(java.lang.Object source,
                                 org.junit.jupiter.api.extension.ParameterContext context)
                          throws ArgumentConversionException
        Convert the supplied source object according to the supplied context.
        Parameters:
        source - the source object to convert; may be null
        context - the parameter context where the converted object will be used; never null
        Returns:
        the converted object; may be null but only if the target type is a reference type
        Throws:
        ArgumentConversionException - if an error occurs during the conversion