1 | |
package org.jbehave.core.model; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.Arrays; |
5 | |
import java.util.LinkedHashSet; |
6 | |
import java.util.List; |
7 | |
import java.util.Set; |
8 | |
|
9 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
10 | |
import org.apache.commons.lang.builder.ToStringStyle; |
11 | |
import org.jbehave.core.annotations.AfterScenario.Outcome; |
12 | |
|
13 | |
public class Lifecycle { |
14 | |
|
15 | 1 | public static final Lifecycle EMPTY = new Lifecycle(); |
16 | |
|
17 | |
private Steps before; |
18 | |
private Steps[] after; |
19 | |
|
20 | |
public Lifecycle() { |
21 | 1 | this(Steps.EMPTY); |
22 | 1 | } |
23 | |
|
24 | 8 | public Lifecycle(Steps before, Steps... after) { |
25 | 8 | this.before = before; |
26 | 8 | this.after = after; |
27 | 8 | } |
28 | |
|
29 | |
public List<String> getBeforeSteps() { |
30 | 53 | return before.steps; |
31 | |
} |
32 | |
|
33 | |
public List<String> getAfterSteps() { |
34 | 7 | List<String> afterSteps = new ArrayList<String>(); |
35 | 18 | for (Steps steps : after) { |
36 | 11 | afterSteps.addAll(steps.steps); |
37 | |
} |
38 | 7 | return afterSteps; |
39 | |
} |
40 | |
|
41 | |
public Set<Outcome> getOutcomes(){ |
42 | 0 | Set<Outcome> outcomes = new LinkedHashSet<Outcome>(); |
43 | 0 | for ( Steps steps : after ){ |
44 | 0 | outcomes.add(steps.outcome); |
45 | |
} |
46 | 0 | return outcomes; |
47 | |
} |
48 | |
|
49 | |
public List<String> getAfterSteps(Outcome outcome) { |
50 | 153 | List<String> afterSteps = new ArrayList<String>(); |
51 | 198 | for (Steps steps : after) { |
52 | 45 | if ( outcome.equals(steps.outcome) ){ |
53 | 15 | afterSteps.addAll(steps.steps); |
54 | |
} |
55 | |
} |
56 | 153 | return afterSteps; |
57 | |
} |
58 | |
|
59 | |
public boolean isEmpty() { |
60 | 106 | return EMPTY == this; |
61 | |
} |
62 | |
|
63 | |
@Override |
64 | |
public String toString() { |
65 | 6 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
66 | |
} |
67 | |
|
68 | 124 | public static class Steps { |
69 | |
|
70 | 1 | public static Steps EMPTY = new Steps(Arrays.<String>asList()); |
71 | |
|
72 | |
private Outcome outcome; |
73 | |
private List<String> steps; |
74 | |
|
75 | |
public Steps(List<String> steps) { |
76 | 5 | this(null, steps); |
77 | 5 | } |
78 | |
|
79 | 17 | public Steps(Outcome outcome, List<String> steps) { |
80 | 17 | this.outcome = outcome; |
81 | 17 | this.steps = steps; |
82 | 17 | } |
83 | |
|
84 | |
@Override |
85 | |
public String toString() { |
86 | 12 | return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); |
87 | |
} |
88 | |
|
89 | |
} |
90 | |
|
91 | |
} |