3
3
import static org .hamcrest .CoreMatchers .equalTo ;
4
4
import static org .junit .Assert .assertThat ;
5
5
6
+ import io .cucumber .datatable .DataTable ;
7
+ import java .util .List ;
6
8
import java .util .Map ;
9
+ import java .util .Objects ;
7
10
8
11
public class TypeDefinitionsStepdefs implements En {
9
12
public TypeDefinitionsStepdefs () {
10
- Given ("docstring, defined with lambda" ,
13
+ Given ("docstring, defined by lambda" ,
11
14
(StringBuilder builder ) -> assertThat (builder .getClass (), equalTo (StringBuilder .class )));
12
15
DocStringType ("doc" , (String docString ) -> new StringBuilder (docString ));
13
16
14
17
DataTableType ((Map <String , String > entry ) -> {
15
18
return new Author (entry .get ("name" ), entry .get ("surname" ), entry .get ("famousBook" ));
16
19
});
17
20
18
- Given ("data table, defined with lambda" , (Author author ) -> {
21
+ Given ("single entry data table, defined by lambda" , (Author author ) -> {
19
22
assertThat (author .name , equalTo ("Fedor" ));
20
23
assertThat (author .surname , equalTo ("Dostoevsky" ));
21
24
assertThat (author .famousBook , equalTo ("Crime and Punishment" ));
22
25
});
23
26
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
+
24
35
Given ("{stringbuilder} parameter, defined by lambda" , (StringBuilder builder ) -> {
25
36
assertThat (builder .toString (), equalTo ("stringbuilder" ));
26
37
});
@@ -39,5 +50,20 @@ public Author(String name, String surname, String famousBook) {
39
50
this .surname = surname ;
40
51
this .famousBook = famousBook ;
41
52
}
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
+ }
42
68
}
43
69
}
0 commit comments