use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldConvertMultilineTableToParameters.
@Test
public void shouldConvertMultilineTableToParameters() {
ParameterConverter converter = new ExamplesTableParametersConverter(new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()));
Type type = new TypeLiteral<List<MyParameters>>() {
}.getType();
assertThatTypesAreAccepted(converter, type);
String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
@SuppressWarnings("unchecked") List<MyParameters> parameters = (List<MyParameters>) converter.convertValue(value, type);
assertThat(parameters.size(), is(2));
MyParameters row1 = parameters.get(0);
assertThat(row1.col1, is("row11"));
assertThat(row1.col2, is("row12"));
MyParameters row2 = parameters.get(1);
assertThat(row2.col1, is("row21"));
assertThat(row2.col2, is("row22"));
}
use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldDefineDefaultConverters.
@SuppressWarnings("unchecked")
@Test
public void shouldDefineDefaultConverters() {
LoadFromClasspath resourceLoader = new LoadFromClasspath();
TableTransformers tableTransformers = new TableTransformers();
ParameterControls parameterControls = new ParameterControls();
ParameterConverters converters = new ParameterConverters(resourceLoader, parameterControls, tableTransformers, true);
ParameterConverter<?>[] defaultConverters = converters.defaultConverters(resourceLoader, parameterControls, tableTransformers, Locale.ENGLISH, ",");
assertThatDefaultConvertersInclude(defaultConverters, BooleanConverter.class, NumberConverter.class, StringListConverter.class, DateConverter.class, EnumConverter.class, ExamplesTableConverter.class, ExamplesTableParametersConverter.class);
}
use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldConvertParameterFromMethodReturningValue.
@Test
public void shouldConvertParameterFromMethodReturningValue() throws IntrospectionException {
Method method = SomeSteps.methodFor("aMethodReturningExamplesTable");
ParameterConverter converter = new MethodReturningConverter(method, new SomeSteps());
assertThatTypesAreAccepted(converter, method.getReturnType());
String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
ExamplesTable table = (ExamplesTable) converter.convertValue(value, ExamplesTable.class);
assertThat(table.getRowCount(), is(2));
Map<String, String> row1 = table.getRow(0);
assertThat(row1.get("col1"), is("row11"));
assertThat(row1.get("col2"), is("row12"));
Map<String, String> row2 = table.getRow(1);
assertThat(row2.get("col1"), is("row21"));
assertThat(row2.get("col2"), is("row22"));
}
use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldConvertSinglelineTableToParameters.
@Test
public void shouldConvertSinglelineTableToParameters() {
ParameterConverter converter = new ExamplesTableParametersConverter(new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()));
Type type = MyParameters.class;
assertThatTypesAreAccepted(converter, type);
String value = "|col1|col2|\n|row11|row12|\n";
MyParameters parameters = (MyParameters) converter.convertValue(value, type);
assertThat(parameters.col1, is("row11"));
assertThat(parameters.col2, is("row12"));
}
Aggregations