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

Classes in this File | Line Coverage | Branch Coverage | Complexity
StoryLanes |
100% | 26/26
100% | 10/10
| 1.8571428571428572;1.857
StoryLanes$1 |
100% | 2/2
N/A | N/A
| 1.8571428571428572;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 | 2 |
         public StoryLanes(StoryMaps storyMaps, StoryNameResolver nameResolver) {
20 | 2 |
             this.storyMaps = storyMaps;
21 | 2 |
             this.nameResolver = nameResolver;
22 | 2 |
         }
23 |  |
24 |  |
         public List<Story> getStories() {
25 | 2 |
             List<Story> stories = new ArrayList<Story>(laneStories("")); // returns all stories
26 | 4 |
             Collections.sort(stories, new Comparator<Story>() {
27 |  |
                 public int compare(Story o1, Story o2) {
28 | 2 |
                     return o1.getName().compareTo(o2.getName());
29 |  |
                 }
30 |  |
             });
31 | 2 |
             return stories;
32 |  |
         }
33 |  |
34 |  |
         public List<String> getLanes() {
35 | 3 |
             List<String> lanes = storyMaps.getMetaFilters();
36 | 3 |
             lanes.remove(""); // don't want to display all stories again
37 | 3 |
             Collections.sort(lanes);
38 | 3 |
             return lanes;
39 |  |
         }
40 |  |
41 |  |
         public boolean inLane(String lane, Story story) {
42 | 6 |
             for (Story laneStory : laneStories(lane)) {
43 | 10 |
                 if (laneStory.getPath().equals(story.getPath())) {
44 | 4 |
                     return true;
45 |  |
                 }
46 |  |
             }
47 | 2 |
             return false;
48 |  |
         }
49 |  |
50 |  |
         private List<Story> laneStories(String lane) {
51 | 8 |
             StoryMap storyMap = storyMaps.getMap(lane);
52 | 8 |
             List<Story> stories = new ArrayList<Story>();
53 | 8 |
             if (storyMap == null) {
54 | 3 |
                 for (StoryMap map : storyMaps.getMaps()) {
55 | 3 |
                     stories.addAll(map.getStories());
56 |  |
                 }
57 |  |
             } else {
58 | 5 |
                 stories.addAll(storyMap.getStories());
59 |  |
             }
60 | 8 |
             nameStories(stories);
61 | 8 |
             return stories;
62 |  |
         }
63 |  |
64 |  |
         private void nameStories(List<Story> stories) {
65 | 8 |
             for (Story story : stories) {
66 | 16 |
                 story.namedAs(nameResolver.resolveName(story.getPath()));
67 |  |
             }
68 |  |
69 | 8 |
         }
70 |  |
71 |  |
     }