use of org.jbehave.core.steps.ParameterConverters.MethodReturningConverter in project jbehave-core by jbehave.
the class ExamplesTableBehaviour method shouldConvertParameterValuesOfTableRow.
@Test
public void shouldConvertParameterValuesOfTableRow() throws Exception {
// Given
ExamplesTableFactory factory = createFactory(new MethodReturningConverter(methodFor("convertDate"), this));
// When
String tableAsString = "|one|two|\n|11|22|\n|1/1/2010|2/2/2010|";
ExamplesTable examplesTable = factory.createExamplesTable(tableAsString);
// Then
Parameters integers = examplesTable.getRowAsParameters(0);
assertThat(integers.<Integer>valueAs("one", Integer.class), equalTo(11));
assertThat(integers.<Integer>valueAs("two", Integer.class), equalTo(22));
Parameters dates = examplesTable.getRowAsParameters(1);
assertThat(dates.<Date>valueAs("one", Date.class), equalTo(convertDate("1/1/2010")));
assertThat(dates.<Date>valueAs("two", Date.class), equalTo(convertDate("2/2/2010")));
}
use of org.jbehave.core.steps.ParameterConverters.MethodReturningConverter in project jbehave-core by jbehave.
the class ExamplesTableBehaviour method shouldConvertParameterValuesOfTableRowWithDefaults.
@Test
public void shouldConvertParameterValuesOfTableRowWithDefaults() throws Exception {
// Given
ExamplesTableFactory factory = createFactory(new MethodReturningConverter(methodFor("convertDate"), this));
// When
String tableDefaultsAsString = "|three|\n|99|";
ExamplesTable defaultsTable = factory.createExamplesTable(tableDefaultsAsString);
Parameters defaults = defaultsTable.getRowAsParameters(0);
String tableAsString = "|one|\n|11|\n|22|";
ExamplesTable examplesTable = factory.createExamplesTable(tableAsString).withDefaults(defaults);
// Then
Parameters firstRow = examplesTable.getRowAsParameters(0);
Map<String, String> firstRowValues = firstRow.values();
assertThat(firstRowValues.containsKey("one"), is(true));
assertThat(firstRow.<String>valueAs("one", String.class), is("11"));
assertThat(firstRow.<Integer>valueAs("one", Integer.class), is(11));
assertThat(firstRowValues.containsKey("three"), is(true));
assertThat(firstRow.<String>valueAs("three", String.class), is("99"));
assertThat(firstRow.<Integer>valueAs("three", Integer.class), is(99));
assertThat(firstRowValues.containsKey("XX"), is(false));
assertThat(firstRow.valueAs("XX", Integer.class, 13), is(13));
Parameters secondRow = examplesTable.getRowAsParameters(1);
Map<String, String> secondRowValues = secondRow.values();
assertThat(secondRowValues.containsKey("one"), is(true));
assertThat(secondRow.<String>valueAs("one", String.class), is("22"));
assertThat(secondRow.<Integer>valueAs("one", Integer.class), is(22));
assertThat(secondRowValues.containsKey("three"), is(true));
assertThat(secondRow.<String>valueAs("three", String.class), is("99"));
assertThat(secondRow.<Integer>valueAs("three", Integer.class), is(99));
assertThat(secondRowValues.containsKey("XX"), is(false));
assertThat(secondRow.valueAs("XX", Integer.class, 13), is(13));
}
use of org.jbehave.core.steps.ParameterConverters.MethodReturningConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldFailToConvertParameterFromFailingMethodReturningValue.
@Test
public void shouldFailToConvertParameterFromFailingMethodReturningValue() throws IntrospectionException {
expectedException.expect(ParameterConvertionFailed.class);
Method method = SomeSteps.methodFor("aFailingMethodReturningExamplesTable");
ParameterConverter converter = new MethodReturningConverter(method, new SomeSteps());
String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
converter.convertValue(value, ExamplesTable.class);
}
use of org.jbehave.core.steps.ParameterConverters.MethodReturningConverter 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"));
}
Aggregations