public class SpockitoValueConverter extends Object implements ValueConverter
Converters.
Constom value converter implementations may want to extend this class and add additional converters by overriding
initConverterFunctions(). Converters for single types can be registered via
registerConverterFunction(Class, Function) and the more generic
registerConverter(BiPredicate, ValueConverter).
| Modifier and Type | Field and Description |
|---|---|
static SpockitoValueConverter |
DEFAULT_INSTANCE |
| Constructor and Description |
|---|
SpockitoValueConverter() |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
convert(Class<T> type,
Type genericType,
String value)
Converts the given string value into the target type specified by raw and generic type.
|
protected void |
initConverterFunctions()
Registers converters for individual types via calls to
registerConverterFunction(Class, Function) and the more generic
registerConverter(BiPredicate, ValueConverter). |
protected void |
registerConverter(BiPredicate<Class<?>,? super Type> applicable,
ValueConverter converter)
Register a value converter for some subgroup of types selected for by the given predicate.
|
protected <T> void |
registerConverterFunction(Class<T> type,
Function<? super String,? extends T> converter)
Register a conversion fuction for the specified type.
|
public static final SpockitoValueConverter DEFAULT_INSTANCE
public SpockitoValueConverter()
public <T> T convert(Class<T> type, Type genericType, String value)
ValueConverterconvert in interface ValueConverterT - the target type parametertype - the target type in raw form, for instance int.class, List.class etc.genericType - the generic target type, same as type for non-generic types; generic type examples are
List<String>, Map<String, Integer> etc.value - the value to convert, may be nullprotected void initConverterFunctions()
registerConverterFunction(Class, Function) and the more generic
registerConverter(BiPredicate, ValueConverter). All converters registered by this method are defined by
Converters.protected <T> void registerConverterFunction(Class<T> type, Function<? super String,? extends T> converter)
T - the targe parametertype - the target typeconverter - a function converting from string to target typeprotected void registerConverter(BiPredicate<Class<?>,? super Type> applicable, ValueConverter converter)
Value converters registered via this method will be queried in registration order. If two converters are applicable to some value, the first whose predicate returns true will be used.
applicable - a predicate returning true if the specified converter can be applied for a value of the
type/generic-type passed to the predicate, and false otherwiseconverter - a value converter from string to target type