Skip to content

Commit 9251ef0

Browse files
author
Anton Deryabin
committed
more tests
1 parent 0e27023 commit 9251ef0

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

java8/src/test/java/io/cucumber/java8/TypeDefinitionsStepdefs.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,35 @@
33
import static org.hamcrest.CoreMatchers.equalTo;
44
import static org.junit.Assert.assertThat;
55

6+
import io.cucumber.datatable.DataTable;
7+
import java.util.List;
68
import java.util.Map;
9+
import java.util.Objects;
710

811
public class TypeDefinitionsStepdefs implements En{
912
public TypeDefinitionsStepdefs() {
10-
Given("docstring, defined with lambda",
13+
Given("docstring, defined by lambda",
1114
(StringBuilder builder) -> assertThat(builder.getClass(), equalTo(StringBuilder.class)));
1215
DocStringType("doc", (String docString) -> new StringBuilder(docString));
1316

1417
DataTableType((Map<String, String> entry) -> {
1518
return new Author(entry.get("name"), entry.get("surname"), entry.get("famousBook"));
1619
});
1720

18-
Given("data table, defined with lambda", (Author author) -> {
21+
Given("single entry data table, defined by lambda", (Author author) -> {
1922
assertThat(author.name, equalTo("Fedor"));
2023
assertThat(author.surname, equalTo("Dostoevsky"));
2124
assertThat(author.famousBook, equalTo("Crime and Punishment"));
2225
});
2326

27+
Given("data table, defined by lambda", (DataTable dataTable) -> {
28+
List<Author> authors = dataTable.asList(Author.class);
29+
Author dostoevsky = new Author("Fedor","Dostoevsky", "Crime and Punishment");
30+
Author tolstoy = new Author("Lev", "Tolstoy", "War and Peace");
31+
assertThat(authors.get(0), equalTo(dostoevsky));
32+
assertThat(authors.get(1), equalTo(tolstoy));
33+
});
34+
2435
Given("{stringbuilder} parameter, defined by lambda", (StringBuilder builder) -> {
2536
assertThat(builder.toString(), equalTo("stringbuilder"));
2637
});
@@ -39,5 +50,20 @@ public Author(String name, String surname, String famousBook) {
3950
this.surname = surname;
4051
this.famousBook = famousBook;
4152
}
53+
54+
@Override
55+
public boolean equals(Object o) {
56+
if (this == o) return true;
57+
if (o == null || getClass() != o.getClass()) return false;
58+
Author author = (Author) o;
59+
return Objects.equals(name, author.name) &&
60+
Objects.equals(surname, author.surname) &&
61+
Objects.equals(famousBook, author.famousBook);
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
return Objects.hash(name, surname, famousBook);
67+
}
4268
}
4369
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
Feature: Lambda type definition
22

33
Scenario: define docstring type by lambda
4-
Given docstring, defined with lambda
4+
Given docstring, defined by lambda
55
"""doc
66
really long docstring
77
"""
88

9-
Scenario: define data table type by lambda
10-
Given data table, defined with lambda
9+
Scenario: define single entry data table type by lambda
10+
Given single entry data table, defined by lambda
1111
|name | surname | famousBook |
1212
|Fedor | Dostoevsky |Crime and Punishment |
1313

14+
Scenario: define data table type by lambda
15+
Given data table, defined by lambda
16+
|name | surname | famousBook |
17+
|Fedor | Dostoevsky |Crime and Punishment |
18+
|Lev | Tolstoy |War and Peace |
19+
1420
Scenario: define parameter type by lambda
1521
Given stringbuilder parameter, defined by lambda

0 commit comments

Comments
 (0)