JBehave
  1. JBehave
  2. JBEHAVE-260

Improve SpringStepsFactory to allow delegating the CandidateStep creation to other factories

    Details

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

      Description

      Change the SpringStepsFactory so it doesn't create CandidateSteps but rather return bean instances. That way I can have a different way of instanciating CandidateSteps.

      addSteps(new ParameterConverterStepsFactory().createCandidateSteps( new SpringStepsFactory(context).createStepsInstances() ));
      

      And the simplified SpringStepsFactory :

      public class SpringStepsFactory {
          private final ListableBeanFactory parent;
          
          public SpringStepsFactory(ListableBeanFactory parent) {    	
          	this.parent = parent;
          }
      
          public Object[] createStepsInstances() {
              List<Object> steps = new ArrayList<Object>();
              for (String name : parent.getBeanDefinitionNames()) {
                  Object bean = parent.getBean(name);
                  if (containsScenarioAnnotations(bean.getClass())) {
                      steps.add(bean);
                  }
              }
              return steps.toArray(new Object[steps.size()]);
          }
             
          private boolean containsScenarioAnnotations(Class<?> componentClass) {
              for (Method method : componentClass.getMethods()) {
                  for (Annotation annotation : method.getAnnotations()) {
                      if (annotation.annotationType().getName().startsWith("org.jbehave.scenario.annotations")) {
                          return true;
                      }
                  }
              }
              return false;
          }
      }
      

        Activity

        Hide
        Mauro Talevi added a comment -

        We could have both methods in the SpringStepsFactory, one that returns Steps object instances and one that returns CandidateSteps.

        Then one could choose which one to use. Would that work?

        Show
        Mauro Talevi added a comment - We could have both methods in the SpringStepsFactory, one that returns Steps object instances and one that returns CandidateSteps. Then one could choose which one to use. Would that work?
        Hide
        Mauro Talevi added a comment -

        SpringStepsFactory provides protected method:

        protected List<Object> stepsInstances();
        
        Show
        Mauro Talevi added a comment - SpringStepsFactory provides protected method: protected List< Object > stepsInstances();
        Mauro Talevi made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 3.0.2 [ 16771 ]
        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: