Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UndefinedDataTableTypeException with Boolean #322

Closed
gaeljw opened this issue Sep 11, 2022 · 5 comments
Closed

UndefinedDataTableTypeException with Boolean #322

gaeljw opened this issue Sep 11, 2022 · 5 comments
Labels
🐛 bug Defect / Bug

Comments

@gaeljw
Copy link
Member

gaeljw commented Sep 11, 2022

👓 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 imported io.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

@gaeljw gaeljw added the 🐛 bug Defect / Bug label Sep 11, 2022
@gaeljw
Copy link
Member Author

gaeljw commented Sep 11, 2022

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) }

@gaeljw
Copy link
Member Author

gaeljw commented Sep 11, 2022

See cucumber/cucumber-jvm#2611 for the JVM issue

@ckorakidis
Copy link

Thanks @gaeljw, thought I was missing something.

@ckorakidis
Copy link

Workaround for the time being: dataTable.asScalaMap[String, String].map(r => r._1 -> r._2.contains("true"))

@gaeljw
Copy link
Member Author

gaeljw commented Sep 15, 2022

Fixed with Cucumber Scala 8.10.0

@gaeljw gaeljw closed this as completed Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

2 participants