[ http://jira.codehaus.org/browse/JBEHAVE-258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=216599#action_216599 ]
Bruno Bieth commented on JBEHAVE-258: ------------------------------------- I believe in most cases converters don't need parameters. If I recall the example in the documentation speak about dates. Honestly I don't think you should handle date conversion differently across your scenarios. Of course I'm not saying you should remove the possibility to instanciate converters. So, most of the time you'd have : {code} @ParameterConverters({DateTimeConverter.class,PercentageConverter.class}) public class PersonSteps { //... } {code} As opposed to {code} public class PersonSteps extends Steps { private static final StepsConfiguration configuration = new StepsConfiguration(); public PersonSteps(ClassLoader classLoader) { super(configuration); configuration.useParameterConverters(new ParameterConverters( new DateTimeConverter(),new PercentageConverter())); // define converter for custom type Date } } {code} and as a side note you have to extend Steps (at least that's what the documentation says). > Annotation for ParameterConverter > --------------------------------- > > Key: JBEHAVE-258 > URL: http://jira.codehaus.org/browse/JBEHAVE-258 > Project: JBehave > Issue Type: Improvement > Reporter: Bruno Bieth > > Simplifying adding ParameterConverter to Steps. Here's an example : > {code} > public class DateTimeConverter implements ParameterConverter { > @Override > public boolean accept(Type type) { > return type.equals( DateTime.class ); > } > @Override > public Object convertValue(String value, Type type) { > return new DateTime( value ); > } > } > {code} > {code} > @ParameterConverters(DateTimeConverter.class) > public class PersonSteps { > private Person person; > private DateTime currentDate; > // ... steps > } > {code} > The ParameterConverters annotation takes an array of TypeConverter : > {code} > @Retention(RetentionPolicy.RUNTIME) > @Target(ElementType.TYPE) > public @interface ParameterConverters { > Class<? extends ParameterConverter>[] value(); > } > {code} > Here is a steps factory : > {code} > public class ParameterConverterStepsFactory { > public CandidateSteps[] createCandidateSteps(Object... stepsInstances) > throws InstantiationException, IllegalAccessException { > CandidateSteps[] candidateSteps = new > CandidateSteps[stepsInstances.length]; > for (int i = 0; i < stepsInstances.length; i++) { > Object stepsInstance = stepsInstances[i]; > StepsConfiguration configuration; > > ParameterConverters parameterConverters = > stepsInstance.getClass().getAnnotation( > ParameterConverters.class ); > > if( parameterConverters != null ) { > configuration = createConfiguration( > parameterConverters ); > } else { > configuration = new StepsConfiguration(); > } > > candidateSteps[i] = new Steps(configuration, stepsInstance); > } > return candidateSteps; > } > private StepsConfiguration createConfiguration( > ParameterConverters annotation) throws > InstantiationException, IllegalAccessException { > ParameterConverter[] converters = new ParameterConverter[ > annotation.value().length ]; > for( int i = 0; i < converters.length; i ++ ) { > converters[ i ] = annotation.value()[ i ].newInstance(); > } > org.jbehave.scenario.steps.ParameterConverters > converterAggregate = > new org.jbehave.scenario.steps.ParameterConverters( > converters ); > return new StepsConfiguration( converterAggregate ); > } > } > {code} -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email