-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[Java] Convert title case headers to property names #1751
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I don't think extending JavaDefaultDataTableEntryTransformerDefinition
with a JavaDefaultDataTableCapitalCaseTransformerDefinition
is the right solution though.
Inheritance should only be used when there is a clear 'is a' relationship between classes. In this case this relation ship is not so clear to me. They are both obviously DefaultDataTableEntryTransformerDefinition
s but the functionality of JavaDefaultDataTableCapitalCaseTransformerDefinition
is a strict subset of JavaDefaultDataTableCapitalCaseTransformerDefinition
s functionality. In these scenarios is better to prefer composition over inheritance and use a decorator pattern.
You could implement a DefaultDataTableEntryTransformerDefinition
that delegates all calls to another instance of DefaultDataTableEntryTransformerDefinition
(in this case always a JavaDefaultDataTableCapitalCaseTransformerDefinition
) and decorates the execute call.
However when you open up a class for extension, or compose it in another class you also have to write tests to see if the extension/composition behaves in the same way the parent class does. This generally makes for some complicated test suits.
And given the simplicity of it all I don't think that either composition or inheritance is worth the structural cost. Adding a boolean as field to JavaDefaultDataTableEntryTransformerDefinition
should be sufficient.
java/src/main/java/io/cucumber/java/DefaultDataTableEntryTransformer.java
Outdated
Show resolved
Hide resolved
java/src/main/java/io/cucumber/java/JavaDefaultDataTableCapitalCaseTransformerDefinition.java
Outdated
Show resolved
Hide resolved
java/src/main/java/io/cucumber/java/JavaDefaultDataTableCapitalCaseTransformerDefinition.java
Outdated
Show resolved
Hide resolved
java/src/main/java/io/cucumber/java/JavaDefaultDataTableCapitalCaseTransformerDefinition.java
Outdated
Show resolved
Hide resolved
java/src/main/java/io/cucumber/java/JavaDefaultDataTableCapitalCaseTransformerDefinition.java
Outdated
Show resolved
Hide resolved
java/src/test/java/io/cucumber/java/defaultstransformer/DataTableSteps.java
Show resolved
Hide resolved
java/src/test/java/io/cucumber/java/JavaDefaultDataTableEntryTransformerDefinitionTest.java
Outdated
Show resolved
Hide resolved
Added an exception to deal with collisions when converting headers and moved the camel case conversion to core so the different backends don't have to deal with individually. |
And with that I think we're done. @rasklaad is there anything you'd think we should add? |
Nah, I think we are fine |
Cool. Cheers. Much appreciated! |
@mpkorstanje I've been trying to piece together what needs to be done in order to make use of this lovely functionality. I've got a table with columns in title case e.g. "Order Id", "Customer Id" I've got a object like:
I've got a step definition which takes Do I need to register default table transformer or should it work out the box? |
Yes. Using the annotation. |
sorry, may sound like a stupid question but where do you register this? Are you saying the step needs to be annotated? (By the way it's a Java 8 style step) |
It's alright. I worked it out. |
Summary
User can convert data table title case header, using default data table transformer
Motivation and Context
#1746
Types of changes
Checklist: