Note that there are some explanatory texts on larger screens.

plurals
  1. PODataTable.diff( List<Map> ) or List<String[]> in cucumber-jvm
    primarykey
    data
    text
    <p>I'm currently porting a test suite originally written in ruby to java.</p> <h1>List&lt;String[]></h1> <p>The first step I'm trying to port parses CSV data into a <code>List&lt;String[]&gt;</code></p> <pre><code>@Then("test 1") public void test1( DataTable expectedTable ) { List&lt;String[]&gt; tableData = getCsvData( fileName ); // I have also tried List&lt;Map&lt;String,String&gt;&gt; here. // when List&lt;String[]&gt; includes the column names in element 0, TableConverter.toTable() // for List&lt;Map&lt;String,String&gt;&gt;, 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 ); } </code></pre> <p>...cucumber-jvm does not display the actual CSV data correctly.</p> <h1>List&lt;Map&lt;String,String>></h1> <p>In our ruby implementation other test steps use <code>Cucumber::Ast::Table.diff!</code> to display reasons for failure:</p> <pre><code>failure = {'line number' =&gt; line, 'reason' =&gt; 'bad data in column 2', 'data' =&gt; column2} failures.push failure Cucumber::Ast::Table.new([[]]).diff!( failures, {surplus_col: true, surplus_row: true} ) unless failures.empty? </code></pre> <p>I've tried to port this to java using <code>java.util.Map</code>, as shown below. The trouble is that although cucumber-jvm identifies that there is a difference between the empty <code>DataTable</code> and my <code>List</code> of <code>Map</code>s, it doesn't parse (or display) my <code>List&lt;Map&gt;</code> correctly.</p> <pre><code>Map&lt;String,String&gt; failure = new HashMap&lt;String,String&gt;(); failure.put("line number", Integer.toString(line)); failure.put("reason", "bad data in column 2"); failure.put("data", Arrays.toString(column2)); List&lt;Map&lt;String,String&gt; failures = new ArrayList&lt;Map&lt;String,String&gt;&gt;(); 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&lt;Map&lt;String, String&gt;&gt; emptyList = new ArrayList&lt;Map&lt;String,String&gt;&gt;(); HashMap&lt;String, String&gt; emptyData = new HashMap&lt;String, String&gt;(); 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 ); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload