Coverage Report - org.jbehave.core.embedder.MatchingStepMonitor
 
Classes in this File Line Coverage Branch Coverage Complexity
MatchingStepMonitor
100%
11/11
75%
3/4
1.333
MatchingStepMonitor$StepMatch
50%
5/10
N/A
1.333
 
 1  
 package org.jbehave.core.embedder;
 2  
 
 3  
 import java.lang.reflect.Method;
 4  
 import java.util.ArrayList;
 5  
 import java.util.HashMap;
 6  
 import java.util.List;
 7  
 import java.util.Map;
 8  
 
 9  
 import org.apache.commons.lang.builder.EqualsBuilder;
 10  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 11  
 import org.apache.commons.lang.builder.ToStringBuilder;
 12  
 import org.apache.commons.lang.builder.ToStringStyle;
 13  
 import org.jbehave.core.model.StepPattern;
 14  
 import org.jbehave.core.steps.NullStepMonitor;
 15  
 import org.jbehave.core.steps.StepType;
 16  
 
 17  138
 public class MatchingStepMonitor extends NullStepMonitor {
 18  
 
 19  138
     private Map<String, StepMatch> matched = new HashMap<String, StepMatch>();
 20  
 
 21  
     public List<StepMatch> matched() {
 22  138
         return new ArrayList<StepMatch>(matched.values());
 23  
     }
 24  
 
 25  
     public void stepMatchesPattern(String step, boolean matches, StepPattern pattern, Method method,
 26  
             Object stepsInstance) {
 27  57
         if (matches) {
 28  57
             String key = pattern.type() + " " + pattern.annotated();
 29  57
             StepMatch stepMatch = matched.get(key);
 30  57
             if (stepMatch == null) {
 31  36
                 stepMatch = new StepMatch(pattern);
 32  36
                 matched.put(key, stepMatch);
 33  
             }
 34  
         }
 35  57
     }
 36  
 
 37  138
     public static class StepMatch {
 38  
         private final StepType type; // key
 39  
         private final String annotatedPattern; // key
 40  
         @SuppressWarnings("unused")
 41  
         private final String resolvedPattern;
 42  
 
 43  37
         public StepMatch(StepPattern pattern) {
 44  37
             this.type = pattern.type();
 45  37
             this.annotatedPattern = pattern.annotated();
 46  37
             this.resolvedPattern = pattern.resolved();
 47  37
         }
 48  
 
 49  
         @Override
 50  
         public boolean equals(Object o) {
 51  0
             StepMatch that = (StepMatch) o;
 52  0
             return new EqualsBuilder().append(this.type, that.type)
 53  0
                     .append(this.annotatedPattern, that.annotatedPattern).isEquals();
 54  
         }
 55  
 
 56  
         @Override
 57  
         public int hashCode() {
 58  0
             return new HashCodeBuilder().append(type).append(annotatedPattern).toHashCode();
 59  
         }
 60  
 
 61  
         @Override
 62  
         public String toString() {
 63  0
             return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
 64  
         }
 65  
 
 66  
     }
 67  
 
 68  
 }