JBehave
  1. JBehave
  2. JBEHAVE-264

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
        Bruno Bieth made changes -
        Field Original Value New Value
        Attachment ParameterConverterStepsFactory.java [ 48335 ]
        Attachment ParameterConverters.java [ 48336 ]
        Bruno Bieth made changes -
        Attachment ParameterConverterStepsFactory.java [ 48329 ]
        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 { //... }
        Mauro Talevi made changes -
        Fix Version/s 3.0 [ 16302 ]
        Component/s Core [ 11086 ]
        Mauro Talevi made changes -
        Summary Steps could act as parameter converters : add the @ParameterConverter annotation Steps methods as parameter converters when annotated by @AsParameterConverter
        Description Better starting with an example :

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

        It would be interesting to have the Steps definition class also able to provide some converters. This is what the code could look like :
        {code}
        @ParameterConverter
        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 ) {

        }
        {code}

        I've attached the ParameterConverterStepsFactory as it's getting bigger.
        Better starting with an example :

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

        It would be interesting to have the Steps definition class also able to provide some converters. This is what the code could look like :
        {code}
        @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 ) {

        }
        {code}

        I've attached the ParameterConverterStepsFactory as it's getting bigger.
        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!
        Mauro Talevi made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Bruno Bieth
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: