| 1 | |
package org.jbehave.core.steps; |
| 2 | |
|
| 3 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 4 | |
import org.apache.commons.lang.builder.ToStringStyle; |
| 5 | |
import org.jbehave.core.failures.PendingStepFound; |
| 6 | |
import org.jbehave.core.failures.UUIDExceptionWrapper; |
| 7 | |
import org.jbehave.core.model.OutcomesTable.OutcomesFailed; |
| 8 | |
import org.jbehave.core.reporters.StoryReporter; |
| 9 | |
|
| 10 | |
import java.lang.reflect.Method; |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
public abstract class AbstractStepResult implements StepResult { |
| 24 | |
|
| 25 | |
public static class Failed extends AbstractStepResult { |
| 26 | |
|
| 27 | |
public Failed(String step, UUIDExceptionWrapper throwable) { |
| 28 | 10 | super(step, throwable); |
| 29 | 10 | } |
| 30 | |
|
| 31 | |
public Failed(Method method, UUIDExceptionWrapper throwable) { |
| 32 | 3 | super(asString(method), throwable); |
| 33 | 3 | } |
| 34 | |
|
| 35 | |
private static String asString(Method method) { |
| 36 | 3 | return method != null ? method.toGenericString(): ""; |
| 37 | |
} |
| 38 | |
|
| 39 | |
public void describeTo(StoryReporter reporter) { |
| 40 | 7 | if (throwable instanceof OutcomesFailed) { |
| 41 | 1 | reporter.failedOutcomes(parametrisedStep(), ((OutcomesFailed) throwable).outcomesTable()); |
| 42 | |
} else { |
| 43 | 6 | reporter.failed(parametrisedStep(), throwable); |
| 44 | |
} |
| 45 | 7 | } |
| 46 | |
} |
| 47 | |
|
| 48 | |
public static class NotPerformed extends AbstractStepResult { |
| 49 | |
|
| 50 | |
public NotPerformed(String step) { |
| 51 | 20 | super(step); |
| 52 | 20 | } |
| 53 | |
|
| 54 | |
public void describeTo(StoryReporter reporter) { |
| 55 | 7 | reporter.notPerformed(parametrisedStep()); |
| 56 | 7 | } |
| 57 | |
} |
| 58 | |
|
| 59 | |
public static class Pending extends AbstractStepResult { |
| 60 | |
public Pending(String step) { |
| 61 | 14 | this(step, new PendingStepFound(step)); |
| 62 | 14 | } |
| 63 | |
|
| 64 | |
public Pending(String step, PendingStepFound e) { |
| 65 | 15 | super(step, e); |
| 66 | 15 | } |
| 67 | |
|
| 68 | |
public void describeTo(StoryReporter reporter) { |
| 69 | 9 | reporter.pending(parametrisedStep()); |
| 70 | 9 | } |
| 71 | |
} |
| 72 | |
|
| 73 | |
public static class Successful extends AbstractStepResult { |
| 74 | |
|
| 75 | |
public Successful(String string) { |
| 76 | 76 | super(string); |
| 77 | 76 | } |
| 78 | |
|
| 79 | |
public void describeTo(StoryReporter reporter) { |
| 80 | 19 | reporter.successful(parametrisedStep()); |
| 81 | 19 | } |
| 82 | |
|
| 83 | |
} |
| 84 | |
|
| 85 | |
public static class Ignorable extends AbstractStepResult { |
| 86 | |
public Ignorable(String step) { |
| 87 | 4 | super(step); |
| 88 | 4 | } |
| 89 | |
|
| 90 | |
public void describeTo(StoryReporter reporter) { |
| 91 | 1 | reporter.ignorable(step); |
| 92 | 1 | } |
| 93 | |
} |
| 94 | |
|
| 95 | |
public static class Skipped extends AbstractStepResult { |
| 96 | |
|
| 97 | |
public Skipped() { |
| 98 | 20 | super(""); |
| 99 | 20 | } |
| 100 | |
|
| 101 | |
public void describeTo(StoryReporter reporter) { |
| 102 | 1 | } |
| 103 | |
} |
| 104 | |
|
| 105 | |
protected final String step; |
| 106 | |
private String parametrisedStep; |
| 107 | |
protected final UUIDExceptionWrapper throwable; |
| 108 | |
|
| 109 | |
public AbstractStepResult(String step) { |
| 110 | 120 | this(step, null); |
| 111 | 120 | } |
| 112 | |
|
| 113 | 148 | public AbstractStepResult(String step, UUIDExceptionWrapper throwable) { |
| 114 | 148 | this.step = step; |
| 115 | 148 | this.throwable = throwable; |
| 116 | 148 | } |
| 117 | |
|
| 118 | |
public String parametrisedStep() { |
| 119 | 46 | return parametrisedStep != null ? parametrisedStep : step; |
| 120 | |
} |
| 121 | |
|
| 122 | |
public StepResult withParameterValues(String parametrisedStep) { |
| 123 | 68 | this.parametrisedStep = parametrisedStep; |
| 124 | 68 | return this; |
| 125 | |
} |
| 126 | |
|
| 127 | |
public UUIDExceptionWrapper getFailure() { |
| 128 | 38 | return throwable; |
| 129 | |
} |
| 130 | |
|
| 131 | |
@Override |
| 132 | |
public String toString() { |
| 133 | 2 | return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append(parametrisedStep()).toString(); |
| 134 | |
} |
| 135 | |
|
| 136 | |
public static StepResult successful(String step) { |
| 137 | 76 | return new Successful(step); |
| 138 | |
} |
| 139 | |
|
| 140 | |
public static StepResult ignorable(String step) { |
| 141 | 4 | return new Ignorable(step); |
| 142 | |
} |
| 143 | |
|
| 144 | |
public static StepResult pending(String step) { |
| 145 | 14 | return new Pending(step); |
| 146 | |
} |
| 147 | |
|
| 148 | |
public static StepResult pending(String step, PendingStepFound e) { |
| 149 | 1 | return new Pending(step, e); |
| 150 | |
} |
| 151 | |
|
| 152 | |
public static StepResult notPerformed(String step) { |
| 153 | 20 | return new NotPerformed(step); |
| 154 | |
} |
| 155 | |
|
| 156 | |
public static StepResult failed(String step, UUIDExceptionWrapper e) { |
| 157 | 10 | return new Failed(step, e); |
| 158 | |
} |
| 159 | |
|
| 160 | |
public static StepResult failed(Method method, UUIDExceptionWrapper e) { |
| 161 | 3 | return new Failed(method, e); |
| 162 | |
} |
| 163 | |
|
| 164 | |
public static StepResult skipped() { |
| 165 | 20 | return new Skipped(); |
| 166 | |
} |
| 167 | |
|
| 168 | |
} |