Coverage Report - org.jbehave.core.steps.PendingStepMethodGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
PendingStepMethodGenerator
100%
19/19
83%
5/6
2
 
 1  
 package org.jbehave.core.steps;
 2  
 
 3  
 import org.apache.commons.lang.StringEscapeUtils;
 4  
 import org.apache.commons.lang.StringUtils;
 5  
 import org.apache.commons.lang.WordUtils;
 6  
 import org.jbehave.core.annotations.Pending;
 7  
 import org.jbehave.core.configuration.Keywords;
 8  
 import org.jbehave.core.steps.StepCreator.PendingStep;
 9  
 
 10  
 import static java.text.MessageFormat.format;
 11  
 
 12  
 public class PendingStepMethodGenerator {
 13  
 
 14  1
     private static final String[] REMOVABLES = new String[] { " ", "\'", "\"", "\\.", "\\,", "\\;", "\\:", "\\!",
 15  
             "\\|", "<", ">", "\\*", "\\$", "\\\\", "\\/", "\\(", "\\)", "\\{", "\\}", "\\[", "\\]" };
 16  
     private static final String METHOD_SOURCE = "@{0}(\"{1}\")\n@{2}\npublic void {3}()'{'\n  // {4}\n'}'\n";
 17  
 
 18  
     private final Keywords keywords;
 19  
 
 20  3
     public PendingStepMethodGenerator(Keywords keywords) {
 21  3
         this.keywords = keywords;
 22  3
     }
 23  
 
 24  
     public String generateMethod(PendingStep step) {
 25  3
         String stepAsString = step.stepAsString();
 26  3
         String previousNonAndStepAsString = step.previousNonAndStepAsString();
 27  3
         StepType stepType = null;
 28  3
         if (keywords.isAndStep(stepAsString) && previousNonAndStepAsString != null) {
 29  1
             stepType = keywords.stepTypeFor(previousNonAndStepAsString);
 30  
         } else {
 31  2
             stepType = keywords.stepTypeFor(stepAsString);
 32  
         }
 33  3
         String stepPattern = keywords.stepWithoutStartingWord(stepAsString, stepType);
 34  3
         String stepAnnotation = StringUtils.capitalize(stepType.name().toLowerCase());
 35  3
         String methodName = methodName(stepType, stepPattern);
 36  3
         String pendingAnnotation = Pending.class.getSimpleName();
 37  3
         return format(METHOD_SOURCE, stepAnnotation, StringEscapeUtils.escapeJava(stepPattern), pendingAnnotation,
 38  
                 methodName, keywords.pending());
 39  
     }
 40  
 
 41  
     private String methodName(StepType stepType, String stepPattern) {
 42  3
         String name = stepType.name().toLowerCase() + WordUtils.capitalize(stepPattern);
 43  66
         for (String remove : REMOVABLES) {
 44  63
             name = name.replaceAll(remove, "");
 45  
         }
 46  3
         return name;
 47  
     }
 48  
 
 49  
 }