Class DefaultArgumentConverter
- java.lang.Object
-
- org.junit.jupiter.params.converter.DefaultArgumentConverter
-
- All Implemented Interfaces:
ArgumentConverter
@API(status=INTERNAL, since="5.0") public class DefaultArgumentConverter extends java.lang.Object implements ArgumentConverterDefaultArgumentConverteris the default implementation of theArgumentConverterAPI.The
DefaultArgumentConverteris able to convert from strings to a number of primitive types and their corresponding wrapper types (Byte, Short, Integer, Long, Float, and Double), date and time types from thejava.timepackage, and some additional common Java types such asFile,BigDecimal,BigInteger,Currency,Locale,URI,URL,UUID, etc.If the source and target types are identical the source object will not be modified.
- Since:
- 5.0
- See Also:
ArgumentConverter,ConversionSupport
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classDefaultArgumentConverter.LocaleConversionFormat
-
Field Summary
Fields Modifier and Type Field Description private org.junit.jupiter.api.extension.ExtensionContextcontextstatic java.lang.StringDEFAULT_LOCALE_CONVERSION_FORMAT_PROPERTY_NAMEProperty name used to set the format for the conversion ofLocalearguments: "junit.jupiter.params.arguments.conversion.locale.format"private static java.util.function.Function<java.lang.String,DefaultArgumentConverter.LocaleConversionFormat>TRANSFORMER
-
Constructor Summary
Constructors Constructor Description DefaultArgumentConverter(org.junit.jupiter.api.extension.ExtensionContext context)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectconvert(java.lang.Object source, java.lang.Class<?> targetType, java.lang.ClassLoader classLoader)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.(package private) java.lang.Objectconvert(java.lang.String source, java.lang.Class<?> targetType, java.lang.ClassLoader classLoader)private DefaultArgumentConverter.LocaleConversionFormatgetLocaleConversionFormat()
-
-
-
Field Detail
-
DEFAULT_LOCALE_CONVERSION_FORMAT_PROPERTY_NAME
public static final java.lang.String DEFAULT_LOCALE_CONVERSION_FORMAT_PROPERTY_NAME
Property name used to set the format for the conversion ofLocalearguments: "junit.jupiter.params.arguments.conversion.locale.format"Supported Values
bcp_47: uses the IETF BCP 47 language tag format, delegating the conversion toLocale.forLanguageTag(String)iso_639: uses the ISO 639 alpha-2 or alpha-3 language code format, delegating the conversion toLocale(String)
If not specified, the default is
bcp_47.- Since:
- 5.13
- See Also:
- Constant Field Values
-
TRANSFORMER
private static final java.util.function.Function<java.lang.String,DefaultArgumentConverter.LocaleConversionFormat> TRANSFORMER
-
context
private final org.junit.jupiter.api.extension.ExtensionContext context
-
-
Method Detail
-
convert
public final java.lang.Object convert(java.lang.Object source, org.junit.jupiter.api.extension.ParameterContext context)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
-
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
public final java.lang.Object convert(java.lang.Object source, java.lang.Class<?> targetType, java.lang.ClassLoader classLoader)
-
getLocaleConversionFormat
private DefaultArgumentConverter.LocaleConversionFormat getLocaleConversionFormat()
-
convert
java.lang.Object convert(java.lang.String source, java.lang.Class<?> targetType, java.lang.ClassLoader classLoader)
-
-