UndefinedDataTableTypeException with Boolean
gaeljw opened this issue ยท 5 comments
๐ What did you see?
From comment from @ckorakidis at #50 (comment)
Can't use DataTable:
io.cucumber.datatable.UndefinedDataTableTypeException: Can't convert DataTable to Map<java.lang.String, boolean>
I use it like:dataTable.asScalaMap[String, Boolean]in StepDefinitions which extends EN and have importedio.cucumber.scala.Implicits._
โ What did you expect to see?
Cucumber should be able to convert to a map with Boolean (Scala or Java) values.
๐ฆ Which tool/library version are you using?
Cucumber Scala 8.9.0
Cucumber core 7.7.0
๐ฌ How could we reproduce it?
With Scala Booleans
Scenario: As Map of boolean
Given the following table as Scala Map with boolean
| row1 | true |
| row2 | |
| row3 | false | Given("the following table as Scala Map with boolean") { (table: DataTable) =>
val data: Map[String, Option[Boolean]] =
table.asScalaMap[String, Boolean]
val expected = Map(
"row1" -> Some(true),
"row2" -> None,
"row3" -> Some(false)
)
assert(data == expected)
}The error:
io.cucumber.datatable.UndefinedDataTableTypeException: Can't convert DataTable to Map<java.lang.String, boolean>.
[error] Please review these problems:
[error]
[error] - There was no table entry transformer registered for boolean.
[error] Please consider registering a table entry transformer.
[error]
[error] - There was no table cell transformer registered for boolean.
[error] Please consider registering a table cell transformer.
[error]
[error] - There was no default table cell transformer registered to transform boolean.
[error] Please consider registering a default table cell transformer.
[error]
With Java Boolean
Replacing Boolean with java.lang.Boolean does not help, the same error is still present:
io.cucumber.datatable.UndefinedDataTableTypeException: Can't convert DataTable to Map<java.lang.String, java.lang.Boolean>.
[error] Please review these problems:
[error]
[error] - There was no table entry transformer registered for java.lang.Boolean.
[error] Please consider registering a table entry transformer.
[error]
[error] - There was no table cell transformer registered for java.lang.Boolean.
[error] Please consider registering a table cell transformer.
[error]
[error] - There was no default table cell transformer registered to transform java.lang.Boolean.
[error] Please consider registering a default table cell transformer.
[error]
๐ Any additional context?
N/A
Thanks for raising the issue @ckorakidis, next time do not hesitate to open a fresh issue rather than commenting on an already fixed one.
I can reproduce the issue but while I thought it would be related to Scala's Boolean, it also happens with Java's java.lang.Boolean. I will thus forward the issue to Cucumber JVM team.
Though to be fair I'm not sure they will consider this as an issue.
In the meantime, the easier workaround would be to parse as a Map[String, String] and then convert values to boolean:
val data: Map[String, Option[Boolean]] =
table
.asScalaMap[String, String]
.map { case (k, v) => k -> v.map(_.toBoolean) }See cucumber/cucumber-jvm#2611 for the JVM issue
Thanks @gaeljw, thought I was missing something.
Workaround for the time being: dataTable.asScalaMap[String, String].map(r => r._1 -> r._2.contains("true"))
Fixed with Cucumber Scala 8.10.0