use of gherkin.formatter.model.DataTableRow in project cucumber-jvm by cucumber.
the class FromDataTableTest method assigns_null_to_objects_when_empty_except_boolean_special_case.
@Test
public void assigns_null_to_objects_when_empty_except_boolean_special_case() throws Throwable {
Method m = StepDefs.class.getMethod("listOfPrimitiveContainers", List.class);
List<DataTableRow> rows = new ArrayList<DataTableRow>();
rows.add(new DataTableRow(NO_COMMENTS, asList("number", "bool", "bool2"), 1));
rows.add(new DataTableRow(NO_COMMENTS, asList("1", "false", "true"), 2));
rows.add(new DataTableRow(NO_COMMENTS, asList("", "", ""), 3));
StepDefs stepDefs = runStepDef(m, rows);
assertEquals(new Integer(1), stepDefs.listOfPrimitiveContainers.get(0).number);
assertEquals(new Boolean(false), stepDefs.listOfPrimitiveContainers.get(0).bool);
assertEquals(true, stepDefs.listOfPrimitiveContainers.get(0).bool2);
assertEquals(null, stepDefs.listOfPrimitiveContainers.get(1).number);
assertEquals(new Boolean(false), stepDefs.listOfPrimitiveContainers.get(1).bool);
assertEquals(false, stepDefs.listOfPrimitiveContainers.get(1).bool2);
}
use of gherkin.formatter.model.DataTableRow in project activityinfo by bedatadriven.
the class AliasTable method deAlias.
/**
* Replaces strongly named objects in the given table with their
* human-friendly test handles
*
* <p>For example, if your test has a partner called "NRC", the the
* test driver will actually create a partner called something like
* "NRC_5e9823d88d563417" to ensure that any existing state does not
* interfere with the current test run.
*
* <p>This method will replace "NRC_5e9823d88d563417" with "NRC" so that
* the output can be presented back to the user.</p>
*/
public DataTable deAlias(DataTable table) {
List<List<String>> rows = Lists.newArrayList();
for (DataTableRow row : table.getGherkinRows()) {
List<String> cells = Lists.newArrayList();
for (String cell : row.getCells()) {
if (isAlias(cell)) {
cells.add(getTestHandleForAlias(cell));
} else {
cells.add(cell.trim());
}
}
rows.add(cells);
}
return DataTable.create(rows);
}
use of gherkin.formatter.model.DataTableRow in project activityinfo by bedatadriven.
the class TableDataParser method getColumnValues.
public static List<String> getColumnValues(DataTable table, String columnName) {
List<String> headerRow = table.getGherkinRows().get(0).getCells();
int columnIndex = -1;
for (int i = 0; i < headerRow.size(); i++) {
columnIndex = i;
if (headerRow.get(i).equalsIgnoreCase(columnName)) {
break;
}
}
List<String> columnCells = Lists.newArrayList();
if (columnIndex != -1) {
for (DataTableRow row : table.getGherkinRows()) {
columnCells.add(row.getCells().get(columnIndex));
}
}
return columnCells;
}
use of gherkin.formatter.model.DataTableRow in project activityinfo by bedatadriven.
the class UiApplicationDriver method assertTableEquals.
public static void assertTableEquals(DataTable expectedTable, List<DetailsEntry> detailsEntries) {
List<DataTableRow> matchedRows = Lists.newArrayList();
List<DetailsEntry> matchedDetailsEntries = Lists.newArrayList();
for (int i = 1; i < expectedTable.getGherkinRows().size(); i++) {
DataTableRow row = expectedTable.getGherkinRows().get(i);
if (matchedRows.contains(row)) {
continue;
}
for (DetailsEntry detailsEntry : detailsEntries) {
if (matchedDetailsEntries.contains(detailsEntry)) {
continue;
}
if (equals(expectedTable.getGherkinRows().get(0).getCells(), row, detailsEntry.getFieldValues())) {
matchedRows.add(row);
matchedDetailsEntries.add(detailsEntry);
break;
}
}
}
if (matchedRows.size() != (expectedTable.getGherkinRows().size() - 1)) {
// -1 because of first row is header
List<DataTableRow> notMatched = Lists.newArrayList(expectedTable.getGherkinRows());
// remove header
notMatched.remove(expectedTable.getGherkinRows().get(0));
notMatched.removeAll(matchedRows);
String notMatchedString = "";
for (DataTableRow row : notMatched) {
notMatchedString += Joiner.on(" | ").join(row.getCells()) + "\n";
}
throw new AssertionError("Data entry table does not match. Expected: \n" + expectedTable + "\n But got: \n" + DetailsEntry.toString(detailsEntries) + "\n Not matched rows:\n" + notMatchedString);
}
}
use of gherkin.formatter.model.DataTableRow in project activityinfo by bedatadriven.
the class UiApplicationDriver method copyLastRow.
private static DataTable copyLastRow(DataTable dataTable, int quantityOfRowCopy) {
List<List<String>> rows = Lists.newArrayList();
// copy existing rows
for (DataTableRow row : dataTable.getGherkinRows()) {
final List<String> newRow = Lists.newArrayList();
for (String cell : row.getCells()) {
newRow.add(cell);
}
rows.add(newRow);
}
// copy last row
DataTableRow lastRow = dataTable.getGherkinRows().get(dataTable.getGherkinRows().size() - 1);
for (int i = 0; i < (quantityOfRowCopy - 1); i++) {
final List<String> newRow = Lists.newArrayList();
for (String cell : lastRow.getCells()) {
newRow.add(cell);
}
rows.add(newRow);
}
return DataTable.create(rows);
}
Aggregations