Mauro,

I brought the discussion here from the comments in JBEHAVE-398, as most of
it's not actually relevant to that specific issue.

The primary use case for the changes I made in my nested-conversion branch (
https://github.com/dgodfrey/jbehave-core/tree/nested-conversion) isn't so
much about the ListConverter, but about the follow-up change I made, the
ParameterTable. The ListConverter (JBehave-398) was just a happy side effect
I made first to reduce some duplicate code I had in my tests. I completely
understand about breaking backwards compatibility, but it didn't really
occur to me that ParametersConverters was a "published" class when I made
the change.

The real use case is for ParameterTable, which is in the following commit.
It probably would've helped if I committed some examples about this as well.
Essentially I'm using ParameterTable as a replacement for ExamplesTable in
@Given/@When/@Then steps that allows for the following code

public class ConverterSteps {
   @AsParameterConverter
    public void toLocalDate(String dateAsString) {

DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(dateAsText).toLocalDate();
    }
}

public class SomeSteps {
    @Given("some data: $table")
    public void aMethod(ParameterTable table) {
        for (Row each :table.getRows()) {
            Integer id = each.getAs(Integer.class, "id");
            String name = each.get("name", "defaultName"); // defaults to
defaultName if column doesn't exist in table.
            LocalDate dob = each.getAs("Date of Birth", "1990-10-20"); //
uses toLocalDate in ConverterSteps and defaults to 1990-10-20 if column
doesn't exist in table
            doSomethingWithData(id, name, age);
        }
    }
}

This makes it much easier to work with tables, lets me focus the stories on
what's more important, "ignoring" some of the details. I tried just having
my own @AsParameterConverter for ParameterTable, but although
getAs(Integer.class, "id") worked, it wasn't picking up any of the other
@AsParameterConverters I'd defined, so each.getAs(LocalDate.class) wasn't.

The benefits of ListConverter (in my branch) are that I don't need to do
anything to convert a string from a story into a List of any Class*, it just
works, which is how I initially expected JBehave to work. I was a little
surprised when I needed to register my own ParameterConverter for
package.SomeClass and then another ParameterConverter for
List<package.SomeClass> for the list conversions.

I suppose the 2 compatibility breakers are:
* renaming ParametersConverters -> DefaultParametersConverters, easily fixed
by renaming them, although dependencies will be a bit convoluted. I just
couldn't think of a better name for the interface, so went with this
approach.
* and adding the extra parameter to ParameterConverter#convert(), which
isn't so easily fixed with my current implementation.

One question I have, which classes are "published" and which are just public
so they can be accessed between packages?

* Only Classes at the moment I think, maybe need to do a bit of work to let
it convert to nested parameterized types, such as
List<List<package.SomeClass>> or List<Set<package.SomeClass>>. Need to test
this.

Sorry for the wall of text :)

Dan.

Reply via email to