Stepdoc.java

  1. package org.jbehave.core.steps;

  2. import java.lang.reflect.Method;

  3. import org.apache.commons.lang3.builder.CompareToBuilder;
  4. import org.apache.commons.lang3.builder.ToStringBuilder;

  5. /**
  6.  * A Stepdoc represents the documentation on a single {@link StepCandidate},
  7.  * which includes:
  8.  * <ul>
  9.  * <li>the step type</li>
  10.  * <li>the pattern to match the step candidate that is configured in the
  11.  * annotation</li>
  12.  * <li>the method in the steps instance class</li>
  13.  * <li>the steps instance class</li>
  14.  * </ul>
  15.  */
  16. public class Stepdoc implements Comparable<Stepdoc> {

  17.     private StepType stepType;
  18.     private String startingWord;
  19.     private String pattern;
  20.     private Method method;
  21.     private Object stepsInstance;

  22.     public Stepdoc(StepCandidate candidate) {
  23.         this.method = candidate.getMethod();
  24.         this.stepType = candidate.getStepType();
  25.         this.startingWord = candidate.getStartingWord();
  26.         this.pattern = candidate.getPatternAsString();
  27.         this.stepsInstance = candidate.getStepsInstance();
  28.     }

  29.     public StepType getStepType() {
  30.         return stepType;
  31.     }

  32.     public String getStartingWord() {
  33.         return startingWord;
  34.     }

  35.     public String getPattern() {
  36.         return pattern;
  37.     }

  38.     public Method getMethod() {
  39.         return method;
  40.     }

  41.     public Object getStepsInstance() {
  42.         return stepsInstance;
  43.     }

  44.     /**
  45.      * Method signature without "public void" prefix
  46.      *
  47.      * @return The method signature in String format
  48.      */
  49.     public String getMethodSignature() {
  50.         if (method != null) {
  51.             String methodSignature = method.toString();
  52.             return methodSignature.replaceFirst("public void ", "");
  53.         }
  54.         return null;
  55.     }

  56.     @Override
  57.     public String toString() {
  58.         return ToStringBuilder.reflectionToString(this);
  59.     }

  60.     @Override
  61.     public int compareTo(Stepdoc that) {
  62.         return CompareToBuilder.reflectionCompare(this, that);
  63.     }

  64. }