Skip to content

Commit c0227d0

Browse files
authored
Clarify datatable matcher documentation (#3019)
* The actual list of authors should be provided by the SUT * Flip the actual and expected values * Add several missing imports for a complete example
1 parent ba2d278 commit c0227d0

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

datatable-matchers/README.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,31 @@ Add the `datatable-matchers` dependency to your pom.
2222
Use the matcher in your step definition.
2323

2424
```java
25-
import static io.cucumber.datatable.matchers.DataTableHasTheSameRowsAs.hasTheSameRowsAs;
25+
import io.cucumber.datatable.DataTable;
26+
import io.cucumber.java.en.Then;
2627

27-
[...]
28-
29-
private final DataTable expected = DataTable.create(
30-
asList(
31-
asList("Annie M. G.", "Schmidt"),
32-
asList("Roald", "Dahl"),
33-
));
34-
35-
@Then("these authors have registered:")
36-
public void these_authors_have_registered(DataTable registeredAuthors){
37-
assertThat(registeredAuthors, hasTheSameRowsAs(expected).inOrder());
38-
39-
// java.lang.AssertionError:
40-
// Expected: a datable with the same rows
41-
// but: the tables were different
42-
// - | Annie M. G. | Schmidt |
43-
// | Roald | Dahl |
44-
// + | Astrid | Lindgren |
45-
}
28+
import static io.cucumber.datatable.matchers.DataTableHasTheSameRowsAs.hasTheSameRowsAs;
29+
import static java.util.Arrays.asList;
30+
import static org.hamcrest.MatcherAssert.assertThat;
31+
32+
public class StepDefinitions {
33+
34+
// Provided by the system under test
35+
DataTable actual = DataTable.create(asList(
36+
asList("Annie M. G.", "Schmidt"),
37+
asList("Roald", "Dahl")
38+
));
39+
40+
@Then("these authors have registered:")
41+
public void these_authors_have_registered(DataTable expected) {
42+
assertThat(actual, hasTheSameRowsAs(expected).inOrder());
43+
// java.lang.AssertionError:
44+
// Expected: a datable with the same rows
45+
// but: the tables were different
46+
// + | Annie M. G. | Schmidt |
47+
// | Roald | Dahl |
48+
// - | Astrid | Lindgren |
49+
}
50+
}
4651
```
4752

0 commit comments

Comments
 (0)