Coverage Report - org.jbehave.core.model.StoryLanes
 
Classes in this File Line Coverage Branch Coverage Complexity
StoryLanes
58%
14/24
12%
1/8
1.857
StoryLanes$1
50%
1/2
N/A
1.857
 
 1  
 package org.jbehave.core.model;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Collections;
 5  
 import java.util.Comparator;
 6  
 import java.util.List;
 7  
 
 8  
 import org.jbehave.core.io.StoryNameResolver;
 9  
 
 10  
 /**
 11  
  * Represents a <a href="http://en.wikipedia.org/wiki/Swim_lane">Swim Lane</a>
 12  
  * view of {@link StoryMaps}.
 13  
  */
 14  
 public class StoryLanes {
 15  
 
 16  
     private final StoryMaps storyMaps;
 17  
     private final StoryNameResolver nameResolver;
 18  
 
 19  1
     public StoryLanes(StoryMaps storyMaps, StoryNameResolver nameResolver) {
 20  1
         this.storyMaps = storyMaps;
 21  1
         this.nameResolver = nameResolver;
 22  1
     }
 23  
 
 24  
     public List<Story> getStories() {
 25  1
         List<Story> stories = laneStories(""); // returns all stories
 26  1
         Collections.sort(stories, new Comparator<Story>() {
 27  
             public int compare(Story o1, Story o2) {
 28  0
                 return o1.getName().compareTo(o2.getName());
 29  
             }
 30  
         });
 31  1
         return stories;
 32  
     }
 33  
 
 34  
     public List<String> getLanes() {
 35  1
         List<String> lanes = storyMaps.getMetaFilters();
 36  1
         lanes.remove(""); // don't want to display all stories again
 37  1
         Collections.sort(lanes);
 38  1
         return lanes;
 39  
     }
 40  
 
 41  
     public boolean inLane(String lane, Story story) {
 42  0
         for (Story laneStory : laneStories(lane)) {
 43  0
             if (laneStory.getPath().equals(story.getPath())) {
 44  0
                 return true;
 45  
             }
 46  
         }
 47  0
         return false;
 48  
     }
 49  
 
 50  
     private List<Story> laneStories(String lane) {
 51  1
         StoryMap storyMap = storyMaps.getMap(lane);
 52  1
         if (storyMap == null) {
 53  1
             return new ArrayList<Story>();
 54  
         }
 55  0
         List<Story> stories = storyMap.getStories();
 56  0
         nameStories(stories);
 57  0
         return stories;
 58  
     }
 59  
 
 60  
     private void nameStories(List<Story> stories) {
 61  0
         for (Story story : stories) {
 62  0
             story.namedAs(nameResolver.resolveName(story.getPath()));
 63  
         }
 64  
         
 65  0
     }
 66  
 
 67  
 }