Module org.junit.jupiter.params
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 Object
implements ArgumentConverter
DefaultArgumentConverter
is the default implementation of the
ArgumentConverter
API.
The DefaultArgumentConverter
is 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 the
java.time
package, and some additional common Java types such as
File
, 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:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal @Nullable Object
convert
(@Nullable Object source, Class<?> targetType, ClassLoader classLoader) final @Nullable Object
convert
(@Nullable Object source, ParameterContext context) Convert the suppliedsource
object according to the suppliedcontext
.final @Nullable Object
convert
(@Nullable Object source, FieldContext context) Convert the suppliedsource
object according to the suppliedcontext
.
-
Field Details
-
DEFAULT_LOCALE_CONVERSION_FORMAT_PROPERTY_NAME
Property name used to set the format for the conversion ofLocale
arguments: "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:
-
-
Constructor Details
-
DefaultArgumentConverter
-
-
Method Details
-
convert
Description copied from interface:ArgumentConverter
Convert the suppliedsource
object according to the suppliedcontext
.- Specified by:
convert
in interfaceArgumentConverter
- Parameters:
source
- the source object to convert; may benull
context
- the parameter context where the converted object will be supplied; nevernull
- Returns:
- the converted object; may be
null
but only if the target type is a reference type
-
convert
public final @Nullable Object convert(@Nullable Object source, FieldContext context) throws ArgumentConversionException Description copied from interface:ArgumentConverter
Convert the suppliedsource
object according to the suppliedcontext
.- Specified by:
convert
in interfaceArgumentConverter
- Parameters:
source
- the source object to convert; may benull
context
- the field context where the converted object will be injected; nevernull
- 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, Class<?> targetType, ClassLoader classLoader)
-