JBehave

Steps methods as parameter converters when annotated by @AsParameterConverter

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 3.0
  • Component/s: Core
  • Labels:
    None
  • Number of attachments :
    2

Description

Better starting with an example :

Given a series
	- Name : Series 0110
	- NAV : $200
Given an investor Peter
When Peter invests 7500 shares in series Series 0110
Then ...

It would be interesting to have the Steps definition class also able to provide some converters. This is what the code could look like :

@AsParameterConverter
public Person findByFirstName( String firstName ) {
  return personDao.findByFirstName( firstName ); 
}

@When("$person invests $nbShares shares in series $series" )
public void invest(Person person, int nbShares, Series series ) {

}

I've attached the ParameterConverterStepsFactory as it's getting bigger.

Activity

Hide
Bruno Bieth added a comment -

Forgot to mention that this will only work with JBEHAVE-263 fixed.

Show
Bruno Bieth added a comment - Forgot to mention that this will only work with JBEHAVE-263 fixed.
Hide
Bruno Bieth added a comment -

@ParameterConverters can now use any class, either the class implement ParameterConverter or it has to have at least one method annotated with @ParameterConverter

Show
Bruno Bieth added a comment - @ParameterConverters can now use any class, either the class implement ParameterConverter or it has to have at least one method annotated with @ParameterConverter
Hide
Bruno Bieth added a comment - - edited

Just improved @ParameterConverters (see comment above).

Allows things like :

public class DateTimeConverter {
	@ParameterConverter
	public DateTime toDateTime( String value ) {
		return new DateTime( value );
	}	
}
@ParameterConverters(DateTimeConverter.class)
public class PersonSteps {
//...
}
Show
Bruno Bieth added a comment - - edited Just improved @ParameterConverters (see comment above). Allows things like :
public class DateTimeConverter {
	@ParameterConverter
	public DateTime toDateTime( String value ) {
		return new DateTime( value );
	}	
}
@ParameterConverters(DateTimeConverter.class)
public class PersonSteps {
//...
}
Hide
Mauro Talevi added a comment -

Hi Bruno, I've added the functionality to AbstractStepsFactory so it's available to all impls of InjectableStepsFactory, whichever way the steps instances are created. For the moment only the method annotation has been implemented, and not the class annotation. Class-annotated configuration is being addressed by JBEHAVE-265.
Thanks for you very good suggestions!

Show
Mauro Talevi added a comment - Hi Bruno, I've added the functionality to AbstractStepsFactory so it's available to all impls of InjectableStepsFactory, whichever way the steps instances are created. For the moment only the method annotation has been implemented, and not the class annotation. Class-annotated configuration is being addressed by JBEHAVE-265. Thanks for you very good suggestions!

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: