Package org.jbehave.core.steps
Class ParameterConverters
- java.lang.Object
-
- org.jbehave.core.steps.ParameterConverters
-
public class ParameterConverters extends Object
Facade responsible for converting parameter values to Java objects. It allows the registration of several
ParameterConverters.ParameterConverter
instances, and the first one that is found to matches the appropriate parameter type is used.Converters for several Java types are provided out-of-the-box:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ParameterConverters.AbstractListParameterConverter<T>
static class
ParameterConverters.AbstractParameterConverter<S,T>
static class
ParameterConverters.BooleanConverter
static class
ParameterConverters.BooleanListConverter
static class
ParameterConverters.DateConverter
Parses value to aDate
using an injectableDateFormat
(defaults to new SimpleDateFormat("dd/MM/yyyy"))static class
ParameterConverters.EnumConverter
Parses value to anyEnum
static class
ParameterConverters.EnumListConverter
Parses value to list of the sameEnum
, using an injectable value separator (defaults to ",") and trimming each element of the list.static class
ParameterConverters.ExamplesTableConverter
Converts value toExamplesTable
using aExamplesTableFactory
.static class
ParameterConverters.ExamplesTableParametersConverter
Converts ExamplesTable to list of parameters, mapped to annotated custom types.static class
ParameterConverters.FluentEnumConverter
AnParameterConverters.EnumConverter
allowing stories prose to be more natural.static class
ParameterConverters.FromStringParameterConverter<T>
static class
ParameterConverters.FunctionalParameterConverter<S,T>
static class
ParameterConverters.JsonConverter
static class
ParameterConverters.JsonFactory
static class
ParameterConverters.MethodReturningConverter
Invokes method on instance to return value.static class
ParameterConverters.NumberConverter
Converts values to numbers, supporting any subclass ofNumber
(including generic Number type), and it unboxed counterpart, using aNumberFormat
to parse to aNumber
and to convert it to a specific number type: Byte, byte:Number.byteValue()
Short, short:Number.shortValue()
Integer, int:Number.intValue()
Float, float:Number.floatValue()
Long, long:Number.longValue()
Double, double:Number.doubleValue()
BigInteger:BigInteger.valueOf(long)
BigDecimal:BigDecimal.valueOf(double)
If no number format is provided, it defaults toNumberFormat.getInstance()
.static class
ParameterConverters.NumberListConverter
Converts value to list of numbers.static class
ParameterConverters.ParameterConversionFailed
static interface
ParameterConverters.ParameterConverter<S,T>
A parameter converter for generic type of source input and target output.static class
ParameterConverters.StringConverter
static class
ParameterConverters.StringListConverter
Converts value to list of String.
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_COLLECTION_SEPARATOR
static Locale
DEFAULT_NUMBER_FORMAT_LOCAL
static StepMonitor
DEFAULT_STEP_MONITOR
static boolean
DEFAULT_THREAD_SAFETY
-
Constructor Summary
Constructors Constructor Description ParameterConverters()
Creates a ParameterConverters using the default resource loader and table transformers, a SilentStepMonitor, English as Locale and "," as collection separator.ParameterConverters(ResourceLoader resourceLoader)
Creates a ParameterConverters of ParameterConverters using the given resource loader.ParameterConverters(ResourceLoader resourceLoader, TableTransformers tableTransformers)
Creates a ParameterConverters given resource loader and table transformers.ParameterConverters(ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers, boolean threadSafe)
Create a ParameterConverters with given thread-safetyParameterConverters(TableTransformers tableTransformers)
Creates a ParameterConverters using the given table transformers.ParameterConverters(StepMonitor monitor, Keywords keywords, ResourceLoader resourceLoader, ParameterControls parameterControls, TableParsers tableParsers, TableTransformers tableTransformers, Locale locale, String collectionSeparator, boolean threadSafe)
Creates a ParameterConverters for the given StepMonitor, keywords, Locale, list separator and thread-safety.ParameterConverters(StepMonitor monitor, Keywords keywords, ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers)
Creates a ParameterConverters using given StepMonitor, keywords, resource loader and table transformers.ParameterConverters(StepMonitor monitor, Keywords keywords, ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers, Locale locale, String collectionSeparator, boolean threadSafe)
Creates a ParameterConverters for the given StepMonitor, keywords, Locale, list separator and thread-safety.ParameterConverters(StepMonitor monitor, ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers)
Creates a ParameterConverters using given StepMonitor, resource loader and table transformers.ParameterConverters(StepMonitor monitor, ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers, Locale locale, String collectionSeparator, boolean threadSafe)
Creates a ParameterConverters for the given StepMonitor, Locale, list separator and thread-safety.
-
Method Summary
Modifier and Type Method Description ParameterConverters
addConverters(List<? extends ParameterConverters.ParameterConverter> converters)
ParameterConverters
addConverters(ParameterConverters.ParameterConverter... converters)
Object
convert(String value, Type type)
protected ParameterConverters.ParameterConverter[]
defaultConverters(Keywords keywords, ResourceLoader resourceLoader, ParameterControls parameterControls, TableParsers tableParsers, TableTransformers tableTransformers, Locale locale, String collectionSeparator)
ParameterConverters
newInstanceAdding(ParameterConverters.ParameterConverter converter)
-
-
-
Field Detail
-
DEFAULT_STEP_MONITOR
public static final StepMonitor DEFAULT_STEP_MONITOR
-
DEFAULT_NUMBER_FORMAT_LOCAL
public static final Locale DEFAULT_NUMBER_FORMAT_LOCAL
-
DEFAULT_COLLECTION_SEPARATOR
public static final String DEFAULT_COLLECTION_SEPARATOR
- See Also:
- Constant Field Values
-
DEFAULT_THREAD_SAFETY
public static final boolean DEFAULT_THREAD_SAFETY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ParameterConverters
public ParameterConverters()
Creates a ParameterConverters using the default resource loader and table transformers, a SilentStepMonitor, English as Locale and "," as collection separator.
-
ParameterConverters
public ParameterConverters(TableTransformers tableTransformers)
Creates a ParameterConverters using the given table transformers.- Parameters:
tableTransformers
- the table transformers
-
ParameterConverters
public ParameterConverters(ResourceLoader resourceLoader)
Creates a ParameterConverters of ParameterConverters using the given resource loader.- Parameters:
resourceLoader
- the resource loader
-
ParameterConverters
public ParameterConverters(ResourceLoader resourceLoader, TableTransformers tableTransformers)
Creates a ParameterConverters given resource loader and table transformers.- Parameters:
resourceLoader
- the resource loadertableTransformers
- the table transformers
-
ParameterConverters
public ParameterConverters(StepMonitor monitor, ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers)
Creates a ParameterConverters using given StepMonitor, resource loader and table transformers.- Parameters:
monitor
- the StepMonitor to useresourceLoader
- the resource loaderparameterControls
- the parameter controlstableTransformers
- the table transformers
-
ParameterConverters
public ParameterConverters(StepMonitor monitor, Keywords keywords, ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers)
Creates a ParameterConverters using given StepMonitor, keywords, resource loader and table transformers.- Parameters:
monitor
- the StepMonitor to usekeywords
- the keywords to useresourceLoader
- the resource loaderparameterControls
- the parameter controlstableTransformers
- the table transformers
-
ParameterConverters
public ParameterConverters(ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers, boolean threadSafe)
Create a ParameterConverters with given thread-safety- Parameters:
resourceLoader
- the resource loaderparameterControls
- the parameter controlstableTransformers
- the table transformersthreadSafe
- the boolean flag to determine if access toParameterConverters.ParameterConverter
should be thread-safe
-
ParameterConverters
public ParameterConverters(StepMonitor monitor, ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers, Locale locale, String collectionSeparator, boolean threadSafe)
Creates a ParameterConverters for the given StepMonitor, Locale, list separator and thread-safety. When selecting a collectionSeparator, please make sure that this character doesn't have a special meaning in your Locale (for instance "," is used as decimal separator in some Locale)- Parameters:
monitor
- the StepMonitor reporting the conversionsresourceLoader
- the resource loaderparameterControls
- the parameter controlstableTransformers
- the table transformerslocale
- the Locale to use when reading numberscollectionSeparator
- the String to use as collection separatorthreadSafe
- the boolean flag to determine if modification ofParameterConverters.ParameterConverter
should be thread-safe
-
ParameterConverters
public ParameterConverters(StepMonitor monitor, Keywords keywords, ResourceLoader resourceLoader, ParameterControls parameterControls, TableTransformers tableTransformers, Locale locale, String collectionSeparator, boolean threadSafe)
Creates a ParameterConverters for the given StepMonitor, keywords, Locale, list separator and thread-safety. When selecting a collectionSeparator, please make sure that this character doesn't have a special meaning in your Locale (for instance "," is used as decimal separator in some Locale)- Parameters:
monitor
- the StepMonitor reporting the conversionsresourceLoader
- the resource loaderkeywords
- the keywordsparameterControls
- the parameter controlstableTransformers
- the table transformerslocale
- the Locale to use when reading numberscollectionSeparator
- the String to use as collection separatorthreadSafe
- the boolean flag to determine if modification ofParameterConverters.ParameterConverter
should be thread-safe
-
ParameterConverters
public ParameterConverters(StepMonitor monitor, Keywords keywords, ResourceLoader resourceLoader, ParameterControls parameterControls, TableParsers tableParsers, TableTransformers tableTransformers, Locale locale, String collectionSeparator, boolean threadSafe)
Creates a ParameterConverters for the given StepMonitor, keywords, Locale, list separator and thread-safety. When selecting a collectionSeparator, please make sure that this character doesn't have a special meaning in your Locale (for instance "," is used as decimal separator in some Locale)- Parameters:
monitor
- the StepMonitor reporting the conversionsresourceLoader
- the resource loaderkeywords
- the keywordsparameterControls
- the parameter controlstableParsers
- the table parserstableTransformers
- the table transformerslocale
- the Locale to use when reading numberscollectionSeparator
- the String to use as collection separatorthreadSafe
- the boolean flag to determine if modification ofParameterConverters.ParameterConverter
should be thread-safe
-
-
Method Detail
-
defaultConverters
protected ParameterConverters.ParameterConverter[] defaultConverters(Keywords keywords, ResourceLoader resourceLoader, ParameterControls parameterControls, TableParsers tableParsers, TableTransformers tableTransformers, Locale locale, String collectionSeparator)
-
addConverters
public ParameterConverters addConverters(ParameterConverters.ParameterConverter... converters)
-
addConverters
public ParameterConverters addConverters(List<? extends ParameterConverters.ParameterConverter> converters)
-
newInstanceAdding
public ParameterConverters newInstanceAdding(ParameterConverters.ParameterConverter converter)
-
-