Search in sources :

Example 26 with DataTable

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

the class TableDifferTest method diff_set_with_itself_in_different_order.

@Test
public void diff_set_with_itself_in_different_order() {
    DataTable other = otherTableWithDifferentOrder();
    table().unorderedDiff(other);
}
Also used : DataTable(cucumber.api.DataTable) Test(org.junit.Test)

Example 27 with DataTable

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

the class TableDifferTest method shouldFindDifferences.

@Test(expected = TableDiffException.class)
public void shouldFindDifferences() {
    try {
        DataTable otherTable = otherTableWithDeletedAndInserted();
        new TableDiffer(table(), otherTable).calculateDiffs();
    } catch (TableDiffException e) {
        String expected = "" + "Tables were not identical:\n" + "      | Aslak | aslak@email.com      | 123 |\n" + "    - | Joe   | joe@email.com        | 234 |\n" + "    + | Doe   | joe@email.com        | 234 |\n" + "    + | Foo   | schnickens@email.net | 789 |\n" + "      | Bryan | bryan@email.org      | 456 |\n" + "    - | Ni    | ni@email.com         | 654 |\n";
        assertEquals(expected, e.getMessage());
        throw e;
    }
}
Also used : DataTable(cucumber.api.DataTable) Test(org.junit.Test)

Example 28 with DataTable

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

the class TableDifferTest method unordered_diff_with_list_of_pojos_and_camelcase_header_mapping.

@Test
public void unordered_diff_with_list_of_pojos_and_camelcase_header_mapping() {
    String source = "" + "| id | Given Name |\n" + "| 1  | me   |\n" + "| 2  | you  |\n" + "| 3  | jdoe |\n";
    DataTable expected = TableParser.parse(source, null);
    List<TestPojo> actual = new ArrayList<TestPojo>();
    actual.add(new TestPojo(2, "you", 222));
    actual.add(new TestPojo(3, "jdoe", 34545));
    actual.add(new TestPojo(1, "me", 123));
    expected.unorderedDiff(actual);
}
Also used : DataTable(cucumber.api.DataTable) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 29 with DataTable

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

the class TableParser method parse.

public static DataTable parse(String source, ParameterInfo parameterInfo) {
    final List<DataTableRow> rows = new ArrayList<DataTableRow>();
    Lexer l = new En(new Listener() {

        @Override
        public void comment(String comment, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void tag(String tag, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void feature(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void background(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void scenario(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void scenarioOutline(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void examples(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void step(String keyword, String name, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void row(List<String> cells, Integer line) {
            rows.add(new DataTableRow(NO_COMMENTS, cells, line));
        }

        @Override
        public void docString(String contentType, String string, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void eof() {
        }
    });
    l.scan(source);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    return new DataTable(rows, new TableConverter(new LocalizedXStreams(classLoader).get(Locale.US), parameterInfo));
}
Also used : DataTable(cucumber.api.DataTable) Listener(gherkin.lexer.Listener) ArrayList(java.util.ArrayList) En(gherkin.lexer.En) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Lexer(gherkin.lexer.Lexer) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 30 with DataTable

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

the class ToDataTableTest method converts_list_of_beans_with_null_to_table.

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

Aggregations

DataTable (cucumber.api.DataTable)34 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)10 List (java.util.List)7 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 And (cucumber.api.java.en.And)1 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