Coverage Report - org.jbehave.core.steps.AbstractStepResult
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractStepResult
100%
19/19
100%
2/2
1.207
AbstractStepResult$Failed
72%
13/18
50%
4/8
1.207
AbstractStepResult$Ignorable
100%
4/4
N/A
1.207
AbstractStepResult$NotPerformed
100%
4/4
N/A
1.207
AbstractStepResult$Pending
100%
6/6
N/A
1.207
AbstractStepResult$Skipped
100%
3/3
N/A
1.207
AbstractStepResult$Successful
100%
4/4
N/A
1.207
 
 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  
  * Represents the possible step results:
 14  
  * <ul>
 15  
  * <li>Failed</li>
 16  
  * <li>NotPerformed</li>
 17  
  * <li>Pending</li>
 18  
  * <li>Successful</li>
 19  
  * <li>Ignorable</li>
 20  
  * <li>Skipped</li>
 21  
  * </ul>
 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  12
             super(step, throwable);
 29  12
         }
 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
             if (method == null) {
 37  0
                 return "";
 38  
             }
 39  3
             StringBuilder sb = new StringBuilder()
 40  
                     .append(method.getDeclaringClass().getName()).append(".")
 41  
                     .append(method.getName()).append("(");
 42  3
             Class<?>[] types = method.getParameterTypes();
 43  3
             for (int i = 0; i < types.length; i++) {
 44  0
                 Class<?> type = types[i];
 45  0
                 sb.append(type.getName());
 46  0
                 if (i+1 < types.length) {
 47  0
                     sb.append(",");
 48  
                 }
 49  
             }
 50  3
             return sb.append(")").toString();
 51  
         }
 52  
 
 53  
         public void describeTo(StoryReporter reporter) {
 54  9
             if (throwable.getCause() instanceof OutcomesFailed) {
 55  1
                 reporter.failedOutcomes(parametrisedStep(), ((OutcomesFailed) throwable.getCause()).outcomesTable());
 56  
             } else {
 57  8
                 reporter.failed(parametrisedStep(), throwable);
 58  
             }
 59  9
         }
 60  
     }
 61  
 
 62  
     public static class NotPerformed extends AbstractStepResult {
 63  
 
 64  
         public NotPerformed(String step) {
 65  23
             super(step);
 66  23
         }
 67  
 
 68  
         public void describeTo(StoryReporter reporter) {
 69  8
             reporter.notPerformed(parametrisedStep());
 70  8
         }
 71  
     }
 72  
 
 73  
     public static class Pending extends AbstractStepResult {
 74  
         public Pending(String step) {
 75  23
             this(step, new PendingStepFound(step));
 76  23
         }
 77  
 
 78  
         public Pending(String step, PendingStepFound e) {
 79  24
             super(step, e);
 80  24
         }
 81  
 
 82  
         public void describeTo(StoryReporter reporter) {
 83  11
             reporter.pending(parametrisedStep());
 84  11
         }
 85  
     }
 86  
 
 87  
     public static class Successful extends AbstractStepResult {
 88  
 
 89  
         public Successful(String string) {
 90  88
             super(string);
 91  88
         }
 92  
 
 93  
         public void describeTo(StoryReporter reporter) {
 94  23
             reporter.successful(parametrisedStep());
 95  23
         }
 96  
 
 97  
     }
 98  
 
 99  
     public static class Ignorable extends AbstractStepResult {
 100  
         public Ignorable(String step) {
 101  4
             super(step);
 102  4
         }
 103  
 
 104  
         public void describeTo(StoryReporter reporter) {
 105  1
             reporter.ignorable(step);
 106  1
         }
 107  
     }
 108  
 
 109  
     public static class Skipped extends AbstractStepResult {
 110  
 
 111  
         public Skipped() {
 112  40
             super("");
 113  40
         }
 114  
 
 115  
         public void describeTo(StoryReporter reporter) {
 116  1
         }
 117  
     }
 118  
 
 119  
     protected final String step;
 120  
     private String parametrisedStep;
 121  
     protected final UUIDExceptionWrapper throwable;
 122  
 
 123  
     public AbstractStepResult(String step) {
 124  155
         this(step, null);
 125  155
     }
 126  
 
 127  194
     public AbstractStepResult(String step, UUIDExceptionWrapper throwable) {
 128  194
         this.step = step;
 129  194
         this.throwable = throwable;
 130  194
     }
 131  
 
 132  
     public String parametrisedStep() {
 133  56
         return parametrisedStep != null ? parametrisedStep : step;
 134  
     }
 135  
 
 136  
     public StepResult withParameterValues(String parametrisedStep) {
 137  77
         this.parametrisedStep = parametrisedStep;
 138  77
         return this;
 139  
     }
 140  
 
 141  
     public UUIDExceptionWrapper getFailure() {
 142  52
         return throwable;
 143  
     }
 144  
 
 145  
     @Override
 146  
     public String toString() {
 147  2
         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append(parametrisedStep()).toString();
 148  
     }
 149  
 
 150  
     public static StepResult successful(String step) {
 151  87
         return new Successful(step);
 152  
     }
 153  
 
 154  
     public static StepResult ignorable(String step) {
 155  4
         return new Ignorable(step);
 156  
     }
 157  
 
 158  
     public static StepResult pending(String step) {
 159  23
         return new Pending(step);
 160  
     }
 161  
 
 162  
     public static StepResult pending(String step, PendingStepFound e) {
 163  1
         return new Pending(step, e);
 164  
     }
 165  
 
 166  
     public static StepResult notPerformed(String step) {
 167  23
         return new NotPerformed(step);
 168  
     }
 169  
 
 170  
     public static StepResult failed(String step, UUIDExceptionWrapper e) {
 171  12
         return new Failed(step, e);
 172  
     }
 173  
 
 174  
     public static StepResult failed(Method method, UUIDExceptionWrapper e) {
 175  3
         return new Failed(method, e);
 176  
     }
 177  
 
 178  
     public static StepResult skipped() {
 179  40
         return new Skipped();
 180  
     }
 181  
 
 182  
 }