Class AnnotationBasedArgumentConverter<A extends Annotation>
java.lang.Object
org.junit.jupiter.params.converter.AnnotationBasedArgumentConverter<A>
- All Implemented Interfaces:
Consumer<A>,ArgumentConverter,AnnotationConsumer<A>
@API(status=MAINTAINED,
since="5.13.3")
public abstract class AnnotationBasedArgumentConverter<A extends Annotation>
extends Object
implements ArgumentConverter, AnnotationConsumer<A>
AnnotationBasedArgumentConverter is an abstract base class for
ArgumentConverter implementations that also need to consume an
annotation in order to perform the conversion.- Since:
- 5.10
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidprotected abstract @Nullable ObjectConvert the suppliedsourceobject into the suppliedtargetType, based on metadata in the provided annotation.final @Nullable Objectconvert(@Nullable Object source, ParameterContext context) Convert the suppliedsourceobject according to the suppliedcontext.final @Nullable Objectconvert(@Nullable Object source, FieldContext context) Convert the suppliedsourceobject according to the suppliedcontext.
-
Constructor Details
-
AnnotationBasedArgumentConverter
public AnnotationBasedArgumentConverter()
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceConsumer<A extends Annotation>
-
convert
public final @Nullable Object convert(@Nullable Object source, ParameterContext context) throws ArgumentConversionException Description 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 @Nullable Object convert(@Nullable Object source, FieldContext context) throws ArgumentConversionException Description 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
protected abstract @Nullable Object convert(@Nullable Object source, Class<?> targetType, A annotation) throws ArgumentConversionException Convert the suppliedsourceobject into the suppliedtargetType, based on metadata in the provided annotation.- Parameters:
source- the source object to convert; may benulltargetType- the target type the source object should be converted into; nevernullannotation- the annotation to process; nevernull- Returns:
- the converted object; may be
nullbut only if the target type is a reference type - Throws:
ArgumentConversionException- in case an error occurs during the conversion
-