Coverage Report - org.jbehave.core.model.GivenStory
 
Classes in this File Line Coverage Branch Coverage Complexity
GivenStory
100%
21/21
100%
4/4
1.111
 
 1  
 package org.jbehave.core.model;
 2  
 
 3  
 import static java.util.regex.Pattern.DOTALL;
 4  
 import static java.util.regex.Pattern.compile;
 5  
 
 6  
 import java.util.HashMap;
 7  
 import java.util.Map;
 8  
 import java.util.regex.Matcher;
 9  
 import java.util.regex.Pattern;
 10  
 
 11  
 import org.apache.commons.lang.StringUtils;
 12  
 import org.apache.commons.lang.builder.ToStringBuilder;
 13  
 import org.apache.commons.lang.builder.ToStringStyle;
 14  
 
 15  
 public class GivenStory {
 16  
 
 17  
     private final String givenStoryAsString;
 18  42
     private Map<String, String> parameters = new HashMap<String, String>();
 19  
     private String path;
 20  
     private String anchor;
 21  
 
 22  42
     public GivenStory(String givenStoryAsString) {
 23  42
         this.givenStoryAsString = givenStoryAsString;
 24  42
         parse(givenStoryAsString);
 25  42
     }
 26  
 
 27  
     private void parse(String givenStoryAsString) {
 28  42
         Pattern pattern = compile("(.*)\\#\\{(.*?)\\}", DOTALL);
 29  42
         Matcher matcher = pattern.matcher(givenStoryAsString.trim());
 30  42
         if (matcher.matches()) {
 31  4
             path = matcher.group(1).trim();
 32  4
             anchor = matcher.group(2).trim();
 33  
         } else {
 34  38
             path = givenStoryAsString;
 35  38
             anchor = "";
 36  
         }
 37  42
     }
 38  
 
 39  
     public String getPath() {
 40  7
         return path;
 41  
     }
 42  
 
 43  
     public String getAnchor() {
 44  56
         return anchor;
 45  
     }
 46  
 
 47  
     public boolean hasAnchor() {
 48  36
         return !StringUtils.isBlank(anchor);
 49  
     }
 50  
 
 51  
     public Map<String, String> getParameters() {
 52  9
         return parameters;
 53  
     }
 54  
 
 55  
     public void useParameters(Map<String, String> parameters) {
 56  51
         this.parameters = parameters;
 57  51
     }
 58  
 
 59  
     public String asString() {
 60  36
         return givenStoryAsString;
 61  
     }
 62  
 
 63  
     public String toString() {
 64  5
         return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
 65  
     }
 66  
 
 67  
 }