0

I'm currently porting a test suite originally written in ruby to java.

List<String[]>

The first step I'm trying to port parses CSV data into a List<String[]>

@Then("test 1")
public void test1( DataTable expectedTable ) {
  List<String[]> tableData = getCsvData( fileName );
  // I have also tried List<Map<String,String>> here.
  // when List<String[]> includes the column names in element 0, TableConverter.toTable() 
  // for List<Map<String,String>>, TableConverter.toTable() ends up with 
  // writer: { columnNames:(as provided in element 0),
  //           fieldNames: ["entry", "entry", "entry"...]
  //           fieldValues: [colName0, row1Value0, colName1, row1Value1...] }
  // and then ComplexTypeWriter.getValues() calls
  //   int index = fieldNames.indexOf(converter.map(columnName));
  // where columnName is correct, but index is evaluated as -1, so getValues() returns
  //   [, , , ,...]
  // so .diff() displays a table of empty strings.
  expectedTable.diff( tableData );
}

...cucumber-jvm does not display the actual CSV data correctly.

List<Map<String,String>>

In our ruby implementation other test steps use Cucumber::Ast::Table.diff! to display reasons for failure:

failure = {'line number' => line, 'reason' => 'bad data in column 2', 'data' => column2}
failures.push failure
Cucumber::Ast::Table.new([[]]).diff!( failures, {surplus_col: true, surplus_row: true} )    unless failures.empty?

I've tried to port this to java using java.util.Map, as shown below. The trouble is that although cucumber-jvm identifies that there is a difference between the empty DataTable and my List of Maps, it doesn't parse (or display) my List<Map> correctly.

Map<String,String> failure = new HashMap<String,String>();
failure.put("line number", Integer.toString(line));
failure.put("reason", "bad data in column 2");
failure.put("data", Arrays.toString(column2));

List<Map<String,String> failures = new ArrayList<Map<String,String>>();
failures.add(failure);

// We're expecting an empty list of failures, so create one to compare against.
String[] columnNames = failures.get(0).keySet().toArray(new String[]{});
ArrayList<Map<String, String>> emptyList = new ArrayList<Map<String,String>>();
HashMap<String, String> emptyData = new HashMap<String, String>();

for( String columnName : failures.get(0).keySet() ) {
    emptyData.put(columnName, null);
}

emptyList.add(emptyData);
DataTable empty = DataTable.create( emptyList, Locale.getDefault(), columnNames );

empty.diff( failures );
4

1 に答える 1

0

これのサポートを実装しました:

https://github.com/cucumber/cucumber-jvm/pull/434

于 2012-12-05T07:17:10.337 に答える