Skip to content

Commit a1cfbca

Browse files
committed
Add more tests on DataTables
1 parent fa5a571 commit a1cfbca

File tree

4 files changed

+129
-1
lines changed

4 files changed

+129
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
Feature: As Cucumber Scala, I want to parse DataTables properly
2+
3+
Scenario: As datatable
4+
Given the following table as DataTable
5+
| key1 | key2 | key3 |
6+
| val11 | val12 | val13 |
7+
| val21 | val22 | val23 |
8+
| val31 | val32 | val33 |
9+
10+
Scenario: As List of Map
11+
Given the following table as List of Map
12+
| key1 | key2 | key3 |
13+
| val11 | val12 | val13 |
14+
| val21 | val22 | val23 |
15+
| val31 | val32 | val33 |
16+
17+
Scenario: As List of List
18+
Given the following table as List of List
19+
| val11 | val12 | val13 |
20+
| val21 | val22 | val23 |
21+
| val31 | val32 | val33 |
22+
23+
Scenario: As Map of Map
24+
Given the following table as Map of Map
25+
| | key1 | key2 | key3 |
26+
| row1 | val11 | val12 | val13 |
27+
| row2 | val21 | val22 | val23 |
28+
| row3 | val31 | val32 | val33 |
29+
30+
Scenario: As Map of List
31+
Given the following table as Map of List
32+
| row1 | val11 | val12 | val13 |
33+
| row2 | val21 | val22 | val23 |
34+
| row3 | val31 | val32 | val33 |
35+
36+
Scenario: As Map
37+
Given the following table as Map
38+
| row1 | val11 |
39+
| row2 | val21 |
40+
| row3 | val31 |
41+
42+
Scenario: As List
43+
Given the following table as List
44+
| val11 |
45+
| val21 |
46+
| val31 |

scala/sources/src/test/scala/tests/datatables/DatatablesSteps.scala renamed to scala/sources/src/test/scala/tests/datatables/DataTableTypeSteps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import io.cucumber.datatable.DataTable
88
import scala.jdk.CollectionConverters._
99

1010

11-
class DatatablesSteps extends ScalaDsl with EN {
11+
class DataTableTypeSteps extends ScalaDsl with EN {
1212

1313
case class GroupOfAuthor(authors: Seq[Author])
1414

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package tests.datatables
2+
3+
import java.util.{List => JavaList, Map => JavaMap}
4+
5+
import io.cucumber.datatable.DataTable
6+
import io.cucumber.scala.{EN, ScalaDsl}
7+
8+
import scala.jdk.CollectionConverters._
9+
10+
class DatatableSteps extends ScalaDsl with EN {
11+
12+
Given("the following table as DataTable") { (table: DataTable) =>
13+
val data: Seq[Map[String, String]] = table.asMaps().asScala.map(_.asScala.toMap).toSeq
14+
val expected = Seq(
15+
Map("key1" -> "val11", "key2" -> "val12", "key3" -> "val13"),
16+
Map("key1" -> "val21", "key2" -> "val22", "key3" -> "val23"),
17+
Map("key1" -> "val31", "key2" -> "val32", "key3" -> "val33")
18+
)
19+
assert(data == expected)
20+
}
21+
22+
Given("the following table as List of Map") { (table: JavaList[JavaMap[String, String]]) =>
23+
val data: Seq[Map[String, String]] = table.asScala.map(_.asScala.toMap).toSeq
24+
val expected = Seq(
25+
Map("key1" -> "val11", "key2" -> "val12", "key3" -> "val13"),
26+
Map("key1" -> "val21", "key2" -> "val22", "key3" -> "val23"),
27+
Map("key1" -> "val31", "key2" -> "val32", "key3" -> "val33")
28+
)
29+
assert(data == expected)
30+
}
31+
32+
Given("the following table as List of List") { (table: JavaList[JavaList[String]]) =>
33+
val data: Seq[Seq[String]] = table.asScala.map(_.asScala.toSeq).toSeq
34+
val expected = Seq(
35+
Seq("val11", "val12", "val13"),
36+
Seq("val21", "val22", "val23"),
37+
Seq("val31", "val32", "val33")
38+
)
39+
assert(data == expected)
40+
}
41+
42+
Given("the following table as Map of Map") { (table: JavaMap[String, JavaMap[String, String]]) =>
43+
val data: Map[String, Map[String, String]] = table.asScala.map { case (k, v) => k -> v.asScala.toMap }.toMap
44+
val expected = Map(
45+
"row1" -> Map("key1" -> "val11", "key2" -> "val12", "key3" -> "val13"),
46+
"row2" -> Map("key1" -> "val21", "key2" -> "val22", "key3" -> "val23"),
47+
"row3" -> Map("key1" -> "val31", "key2" -> "val32", "key3" -> "val33")
48+
)
49+
assert(data == expected)
50+
}
51+
52+
Given("the following table as Map of List") { (table: JavaMap[String, JavaList[String]]) =>
53+
val data: Map[String, Seq[String]] = table.asScala.map { case (k, v) => k -> v.asScala.toSeq }.toMap
54+
val expected = Map(
55+
"row1" -> Seq("val11", "val12", "val13"),
56+
"row2" -> Seq("val21", "val22", "val23"),
57+
"row3" -> Seq("val31", "val32", "val33")
58+
)
59+
assert(data == expected)
60+
}
61+
62+
Given("the following table as Map") { (table: JavaMap[String, String]) =>
63+
val data: Map[String, String] = table.asScala.toMap
64+
val expected = Map(
65+
"row1" -> "val11",
66+
"row2" -> "val21",
67+
"row3" -> "val31"
68+
)
69+
assert(data == expected)
70+
}
71+
72+
Given("the following table as List") { (table: JavaList[String]) =>
73+
val data: Seq[String] = table.asScala.toSeq
74+
val expected = Seq(
75+
"val11",
76+
"val21",
77+
"val31"
78+
)
79+
assert(data == expected)
80+
}
81+
82+
}

0 commit comments

Comments
 (0)