use of org.jbehave.core.steps.Parameters 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.Parameters in project jbehave-core by jbehave.
the class ExamplesTableBehaviour method shouldParseTableWithBlankValues.
@Test
public void shouldParseTableWithBlankValues() {
String tableWithEmptyValues = "|one|two|\n |||\n | ||\n || |\n";
ExamplesTable table = new ExamplesTable(tableWithEmptyValues);
assertThat(table.getRowCount(), equalTo(3));
for (Parameters row : table.getRowsAsParameters()) {
Map<String, String> values = row.values();
assertThat(values.size(), equalTo(2));
for (String column : values.keySet()) {
assertThat(isBlank(values.get(column)), is(true));
}
}
assertThat(table.asString(), equalTo("|one|two|\n|||\n|||\n|||\n"));
}
use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.
the class ExamplesTableBehaviour method shouldAllowAdditionAndModificationOfRowValues.
@Test
public void shouldAllowAdditionAndModificationOfRowValues() throws Exception {
// Given
ExamplesTableFactory factory = createFactory();
// When
String tableAsString = "|one|two|\n|11|12|\n|21|22|";
ExamplesTable examplesTable = factory.createExamplesTable(tableAsString);
Map<String, String> values = new HashMap<>();
values.put("one", "111");
values.put("three", "333");
examplesTable.withRowValues(0, values);
Map<String, String> otherValues = new HashMap<>();
otherValues.put("two", "222");
examplesTable.withRowValues(1, otherValues);
// Then
Parameters firstRow = examplesTable.getRowAsParameters(0);
assertThat(firstRow.<Integer>valueAs("one", Integer.class), equalTo(111));
assertThat(firstRow.<Integer>valueAs("two", Integer.class), equalTo(12));
assertThat(firstRow.<Integer>valueAs("three", Integer.class), equalTo(333));
Parameters secondRow = examplesTable.getRowAsParameters(1);
assertThat(secondRow.<Integer>valueAs("one", Integer.class), equalTo(21));
assertThat(secondRow.<Integer>valueAs("two", Integer.class), equalTo(222));
assertThat(secondRow.<String>valueAs("three", String.class), equalTo(""));
assertThat(examplesTable.asString(), equalTo("|one|two|three|\n|111|12|333|\n|21|222||\n"));
}
use of org.jbehave.core.steps.Parameters in project jbehave-core by jbehave.
the class ExamplesTableBehaviour method shouldParseTableWithCommentsInValues.
@Test
public void shouldParseTableWithCommentsInValues() {
String tableWithEmptyValues = "{commentSeparator=#}\n|one #comment|two|\n |11 #comment|12 #comment|\n |21|22|\n";
ExamplesTable table = new ExamplesTable(tableWithEmptyValues);
assertThat(table.getRowCount(), equalTo(2));
for (Parameters row : table.getRowsAsParameters()) {
Map<String, String> values = row.values();
assertThat(values.size(), equalTo(2));
for (String column : values.keySet()) {
assertThat(values.get(column), not(containsString("#comment")));
}
}
assertThat(table.asString(), equalTo("{commentSeparator=#}\n|one|two|\n|11|12|\n|21|22|\n"));
}
use of org.jbehave.core.steps.Parameters 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));
}
Aggregations