Class TypedArgumentConverter<S, T extends @Nullable Object>

java.lang.Object
org.junit.jupiter.params.converter.TypedArgumentConverter<S,T>
Type Parameters:
S - the type of the source argument to convert
T - 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 @Nullable Object> extends Object implements ArgumentConverter
TypedArgumentConverter is an abstract base class for ArgumentConverter implementations that always convert objects of a given source type into a given target type.
Since:
5.7
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    TypedArgumentConverter(Class<S> sourceType, Class<T> targetType)
    Create a new TypedArgumentConverter.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract T
    convert(@Nullable S source)
    Convert the supplied source object of type S into an object of type T.
    final @Nullable Object
    convert(@Nullable Object source, org.junit.jupiter.api.extension.ParameterContext context)
    Convert the supplied source object according to the supplied context.
    final @Nullable Object
    convert(@Nullable Object source, FieldContext context)
    Convert the supplied source object according to the supplied context.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TypedArgumentConverter

      protected TypedArgumentConverter(Class<S> sourceType, Class<T> targetType)
      Create a new TypedArgumentConverter.
      Parameters:
      sourceType - the type of the argument to convert; never null
      targetType - the type of the target object to create from the source; never null
  • Method Details

    • convert

      public final @Nullable Object convert(@Nullable Object source, org.junit.jupiter.api.extension.ParameterContext context) throws ArgumentConversionException
      Description copied from interface: ArgumentConverter
      Convert the supplied source object according to the supplied context.
      Specified by:
      convert in interface ArgumentConverter
      Parameters:
      source - the source object to convert; may be null
      context - the parameter context where the converted object will be supplied; 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
    • convert

      public final @Nullable Object convert(@Nullable Object source, FieldContext context) throws ArgumentConversionException
      Description copied from interface: ArgumentConverter
      Convert the supplied source object according to the supplied context.
      Specified by:
      convert in interface ArgumentConverter
      Parameters:
      source - the source object to convert; may be null
      context - the field context where the converted object will be injected; 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
    • convert

      protected abstract T convert(@Nullable S source) throws ArgumentConversionException
      Convert the supplied source object of type S into an object of type T.
      Parameters:
      source - the source object to convert; may be 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