Class FallbackStringToObjectConverter
java.lang.Object
org.junit.jupiter.params.converter.FallbackStringToObjectConverter
- All Implemented Interfaces:
DefaultArgumentConverter.StringToObjectConverter
class FallbackStringToObjectConverter
extends Object
implements DefaultArgumentConverter.StringToObjectConverter
FallbackStringToObjectConverter
is a DefaultArgumentConverter.StringToObjectConverter
that provides a fallback conversion strategy for converting from a
String
to a given target type by invoking a static factory method
or factory constructor defined in the target type.
Search Algorithm
- Search for a single, non-private static factory method in the target type that converts from a String to the target type. Use the factory method if present.
- Search for a single, non-private constructor in the target type that accepts a String. Use the constructor if present.
If multiple suitable factory methods are discovered they will be ignored. If neither a single factory method nor a single constructor is found, this converter acts as a no-op.
- Since:
- 5.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
Predicate
that determines if theConstructor
supplied toFallbackStringToObjectConverter.IsFactoryConstructor.test(Constructor)
is a non-private factory constructor for the suppliedFallbackStringToObjectConverter.IsFactoryConstructor.targetType
.(package private) static class
Predicate
that determines if theMethod
supplied toFallbackStringToObjectConverter.IsFactoryMethod.test(Method)
is a non-private static factory method for the suppliedFallbackStringToObjectConverter.IsFactoryMethod.targetType
. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ConcurrentHashMap<Class<?>,
Function<String, Object>> Cache for factory methods and factory constructors.Implementation of the NULL Object Pattern. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canConvert
(Class<?> targetType) private static Constructor<?>
findFactoryConstructor
(Class<?> targetType) findFactoryExecutable
(Class<?> targetType) private static Method
findFactoryMethod
(Class<?> targetType) private static boolean
isNotPrivateAndAcceptsSingleStringArgument
(Executable executable)
-
Field Details
-
NULL_EXECUTABLE
Implementation of the NULL Object Pattern. -
factoryExecutableCache
Cache for factory methods and factory constructors.Searches that do not find a factory method or constructor are tracked by the presence of a
NULL_EXECUTABLE
object stored in the map. This prevents the framework from repeatedly searching for things which are already known not to exist.
-
-
Constructor Details
-
FallbackStringToObjectConverter
FallbackStringToObjectConverter()
-
-
Method Details
-
canConvert
- Specified by:
canConvert
in interfaceDefaultArgumentConverter.StringToObjectConverter
-
convert
- Specified by:
convert
in interfaceDefaultArgumentConverter.StringToObjectConverter
- Throws:
Exception
-
findFactoryExecutable
-
findFactoryMethod
-
findFactoryConstructor
-
isNotPrivateAndAcceptsSingleStringArgument
-