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);
}
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());
}
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());
}
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));
}
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()));
}
}
Aggregations