-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Java] Support empty strings and null values in data tables #1857
Conversation
807e007
to
78e46dd
Compare
Empty data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=null), Author(name="Ancient Author", firstPublication=)] } ```
78e46dd
to
c5d3a87
Compare
e418416
to
40cb73a
Compare
Hi, |
How would that work? |
I believe something like this: Feature: Test examples feature
Scenario Template: Examples with empty values
Given param p="<emptyValue>"
And param x="<nullValue>"
Examples:
| emptyValue | nullValue |
| [_blank] | | and I think 'replaceWithEmptyString' could be made available also for DefaultParameterTransformer: @DefaultParameterTransformer(replaceWithEmptyString = "[_blank]")
public Object defaultTransformer(Object fromValue, Type toValueType) {
return objectMapper.convertValue(fromValue, objectMapper.constructType(toValueType));
} |
That's not what Scenario Outlines do.
Is syntactic sugar for:
If I'm not mistaken you can use an optional capture group to do this.
And with a non-capturing group you can
|
I know, I was referring to the values passed from the examples table to each scenario. |
Summary
Empty data table cells can either be considered null or empty strings.
For example table below can converted to a map as
{name=Aspiring Author, first publication=}
or{name=Aspiring Author, first publication=null}
.Motivation and Context
And as demonstrated #1617 there are good reasons to default the empty
table cell to null. However this does not cover all cases. There are
however good use cases to use the empty string.
Additionally allowing users to replace empty table cells with a
[blank]
willreduce the impact of #1617 and provide a nicer migration pattern.
Details
By declaring a table transformer with a replacement string it becomes
possible to explicitly disambiguate between the two scenarios. For
example:
Todo
DataTable.getDataTableConverter
method so we can recreate data tables.Types of changes
Checklist: