Search in sources :

Example 31 with DataTableRow

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);
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) DataTableRow(gherkin.formatter.model.DataTableRow) Test(org.junit.Test)

Example 32 with DataTableRow

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);
}
Also used : List(java.util.List) Arrays.asList(java.util.Arrays.asList) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 33 with DataTableRow

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;
}
Also used : DataTableRow(gherkin.formatter.model.DataTableRow)

Example 34 with DataTableRow

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);
    }
}
Also used : DataTableRow(gherkin.formatter.model.DataTableRow)

Example 35 with DataTableRow

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);
}
Also used : DataTableRow(gherkin.formatter.model.DataTableRow)

Aggregations

DataTableRow (gherkin.formatter.model.DataTableRow)46 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)9 List (java.util.List)6 And (cucumber.api.java.en.And)5 DataTable (cucumber.api.DataTable)4 DocString (gherkin.formatter.model.DocString)4 Step (gherkin.formatter.model.Step)4 Given (cucumber.api.java.en.Given)3 Then (cucumber.api.java.en.Then)3 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)3 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)3 Argument (gherkin.formatter.Argument)2 Arrays.asList (java.util.Arrays.asList)2 Map (java.util.Map)2 Pair (org.activityinfo.model.util.Pair)2 Usage (alien4cloud.model.common.Usage)1 Delta (cucumber.deps.difflib.Delta)1 I18n (gherkin.I18n)1 Row (gherkin.formatter.model.Row)1