Hi Dan,
On 01/12/2010 12:09, Dan Godfrey wrote:
> 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.
>
I'll have a look at this use case in more detail. Just to recap, you'd
like to have an extension of ExamplesTable that converts parameters for
you on demand, via the getAs(Class,String) method,
and in particular the conversion defined in methods annotated via
@AsParameterConverter, right?
> 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?
>
There is no real distinction between published and not. We want to
avoid that a change breaks the existing behavior. We can evolve and
deprecate something but we want to avoid it not working from one release
to the next.
> * 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.
Thanks for your input.
Cheers
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email