##### Coverage Report - org.jbehave.core.model.GivenStory

Classes in this File | Line Coverage | Branch Coverage | Complexity
GivenStory |
100% | 21/21
100% | 4/4
| 1.1111111111111112;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 | 54 |
         private Map<String, String> parameters = new HashMap<String, String>();
19 |  |
         private String path;
20 |  |
         private String anchor;
21 |  |
22 | 54 |
         public GivenStory(String givenStoryAsString) {
23 | 54 |
             this.givenStoryAsString = givenStoryAsString.trim();
24 | 54 |
             parse();
25 | 54 |
         }
26 |  |
27 |  |
         private void parse() {
28 | 54 |
             Pattern pattern = compile("(.*)\\#\\{(.*?)\\}", DOTALL);
29 | 54 |
             Matcher matcher = pattern.matcher(givenStoryAsString.trim());
30 | 54 |
             if (matcher.matches()) {
31 | 4 |
                 path = matcher.group(1).trim();
32 | 4 |
                 anchor = matcher.group(2).trim();
33 |  |
             } else {
34 | 50 |
                 path = givenStoryAsString;
35 | 50 |
                 anchor = "";
36 |  |
             }
37 | 54 |
         }
38 |  |
39 |  |
         public String getPath() {
40 | 12 |
             return path;
41 |  |
         }
42 |  |
43 |  |
         public String getAnchor() {
44 | 65 |
             return anchor;
45 |  |
         }
46 |  |
47 |  |
         public boolean hasAnchor() {
48 | 42 |
             return !StringUtils.isBlank(anchor);
49 |  |
         }
50 |  |
51 |  |
         public Map<String, String> getParameters() {
52 | 10 |
             return parameters;
53 |  |
         }
54 |  |
55 |  |
         public void useParameters(Map<String, String> parameters) {
56 | 60 |
             this.parameters = parameters;
57 | 60 |
         }
58 |  |
59 |  |
         public String asString() {
60 | 41 |
             return givenStoryAsString;
61 |  |
         }
62 |  |
63 |  |
         public String toString() {
64 | 5 |
             return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
65 |  |
         }
66 |  |
67 |  |
     }