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 #2611

Closed
gaeljw opened this issue Sep 11, 2022 · 2 comments · Fixed by #2614
Closed

UndefinedDataTableTypeException with Boolean #2611

gaeljw opened this issue Sep 11, 2022 · 2 comments · Fixed by #2614
Labels
🐛 bug Defect / Bug

Comments

@gaeljw
Copy link
Member

gaeljw commented Sep 11, 2022

👓 What did you see?

Cucumber is not able to convert DataTable to Map<String, Boolean>.

It fails with following error:

 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] 

✅ What did you expect to see?

To be honest, I'm not sure I personally expect Cucumber to handle this case. But I admit it would be nice to handle conversion to Boolean as other types are handled like String or Integer for instance.

📦 Which tool/library version are you using?

Cucumber Core 7.7.0.

🔬 How could we reproduce it?

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")
public void my_step(DataTable table) {
    Map<String, Boolean> data = table.asMap(String.class, Boolean.class)
    Map<String, Boolean> expected = Map.ofEntries(
      entry("row1", Boolean.TRUE)
      entry("row2", null),
      entry("row3", Boolean.FALSE)
    )
    assert(data == expected)
}

📚 Any additional context?

The issue was actually raised on Scala implementation in the first place: cucumber/cucumber-jvm-scala#322

@gaeljw
Copy link
Member Author

gaeljw commented Sep 11, 2022

If you point me in the right direction, I could probably open a PR to fix it.

I didn't search much yet so I might be saying toal nonsense but would this relate to the types defined at

?

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Sep 11, 2022

Yeah. That's the right spot. Not sure why I never added booleans. Note that they should be replaceable to facilitate converters that work with other boolean strings like yes/no ect. That's what the true flag is for IIRC.

TableCellTransformer<Object> objectTableCellTransformer = applyIfPresent(s -> s);
defineDataTableType(new DataTableType(Object.class, objectTableCellTransformer, true));

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

Successfully merging a pull request may close this issue.

2 participants