Search in sources :

Example 11 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class ToDataTableTest method converts_list_of_list_of_number_to_table.

@Test
public void converts_list_of_list_of_number_to_table() {
    List<? extends List<? extends Number>> lists = asList(asList(0.5, 1.5), asList(99.0, 1000.5));
    DataTable table = tc.toTable(lists);
    assertEquals("" + "      | 0.5 | 1.5     |\n" + "      | 99  | 1,000.5 |\n" + "", table.toString());
    List<List<Double>> actual = tc.toLists(table, Double.class);
    assertEquals(lists, actual);
}
Also used : DataTable(cucumber.api.DataTable) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 12 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class ToDataTableTest method converts_list_of_array_of_string_or_number_to_table_with_number_formatting.

@Test
public void converts_list_of_array_of_string_or_number_to_table_with_number_formatting() {
    List<Object[]> arrays = asList(new Object[] { "name", "birthDate", "credits" }, new Object[] { "Sid Vicious", "10/05/1957", 1000 }, new Object[] { "Frank Zappa", "21/12/1940", 3000 });
    DataTable table = tc.toTable(arrays);
    assertEquals("" + "      | name        | birthDate  | credits |\n" + "      | Sid Vicious | 10/05/1957 | 1,000   |\n" + "      | Frank Zappa | 21/12/1940 | 3,000   |\n" + "", table.toString());
}
Also used : DataTable(cucumber.api.DataTable) Test(org.junit.Test)

Example 13 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class ToDataTableTest method converts_list_of_beans_to_table_with_explicit_columns.

@Test
public void converts_list_of_beans_to_table_with_explicit_columns() {
    List<UserPojo> users = tc.toList(personTable(), UserPojo.class);
    DataTable table = tc.toTable(users, "name", "birthDate", "credits");
    assertEquals("" + "      | name        | birthDate  | credits |\n" + "      | Sid Vicious | 10/05/1957 | 1,000   |\n" + "      | Frank Zappa | 21/12/1940 | 3,000   |\n" + "", table.toString());
}
Also used : DataTable(cucumber.api.DataTable) Test(org.junit.Test)

Example 14 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class TableConverterTest method converts_table_of_two_columns_to_map.

@Test
public void converts_table_of_two_columns_to_map() {
    DataTable table = TableParser.parse("|3|c|\n|5|e|\n|6|f|\n", null);
    Map<Integer, String> expected = new HashMap<Integer, String>() {

        {
            put(3, "c");
            put(5, "e");
            put(6, "f");
        }
    };
    assertEquals(expected, table.asMap(Integer.class, String.class));
}
Also used : DataTable(cucumber.api.DataTable) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 15 with DataTable

use of cucumber.api.DataTable in project cucumber-jvm by cucumber.

the class TableDiffer method calculateUnorderedDiffs.

public void calculateUnorderedDiffs() throws TableDiffException {
    boolean isDifferent = false;
    List<DataTableRow> diffTableRows = new ArrayList<DataTableRow>();
    List<List<String>> missingRow = new ArrayList<List<String>>();
    ArrayList<List<String>> extraRows = new ArrayList<List<String>>();
    // 1. add all "to" row in extra table
    // 2. iterate over "from", when a common row occurs, remove it from extraRows
    // finally, only extra rows are kept and in same order that in "to".
    extraRows.addAll(to.raw());
    int i = 1;
    for (DataTableRow r : from.getGherkinRows()) {
        if (!to.raw().contains(r.getCells())) {
            missingRow.add(r.getCells());
            diffTableRows.add(new DataTableRow(r.getComments(), r.getCells(), i, Row.DiffType.DELETE));
            isDifferent = true;
        } else {
            diffTableRows.add(new DataTableRow(r.getComments(), r.getCells(), i++));
            extraRows.remove(r.getCells());
        }
    }
    for (List<String> e : extraRows) {
        diffTableRows.add(new DataTableRow(Collections.EMPTY_LIST, e, i++, Row.DiffType.INSERT));
        isDifferent = true;
    }
    if (isDifferent) {
        throw new TableDiffException(from, to, new DataTable(diffTableRows, from.getTableConverter()));
    }
}
Also used : DataTable(cucumber.api.DataTable) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DataTableRow(gherkin.formatter.model.DataTableRow)

Aggregations

DataTable (cucumber.api.DataTable)33 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)9 List (java.util.List)6 DataTableRow (gherkin.formatter.model.DataTableRow)4 Arrays.asList (java.util.Arrays.asList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)3 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)2 Type (java.lang.reflect.Type)2 SingleValueConverter (cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter)1 Delta (cucumber.deps.difflib.Delta)1 CucumberException (cucumber.runtime.CucumberException)1 Utils.listItemType (cucumber.runtime.Utils.listItemType)1 Utils.mapKeyType (cucumber.runtime.Utils.mapKeyType)1 Utils.mapValueType (cucumber.runtime.Utils.mapValueType)1 TableConverter (cucumber.runtime.table.TableConverter)1 En (gherkin.lexer.En)1 Lexer (gherkin.lexer.Lexer)1 Listener (gherkin.lexer.Listener)1