01: // Copyright © 2002-2005 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.engine;
03:
04: import org.apache.tools.ant.BuildException;
05:
06: import com.canoo.webtest.steps.Step;
07:
08: public final class StepFailedException extends WebTestException {
09:
10: public StepFailedException(String message) {
11: super (message, (Exception) null);
12: }
13:
14: public StepFailedException(final String message,
15: final String expectedValue, final String actualValue,
16: final Step failedStep) {
17: super (message, ". Expected value \"" + expectedValue
18: + "\" but got \"" + actualValue + "\"", failedStep);
19: addDetail("expected value", expectedValue);
20: addDetail("actual value", actualValue);
21: }
22:
23: public StepFailedException(final String message,
24: final int expectedValue, final int actualValue) {
25: this (message, String.valueOf(expectedValue), String
26: .valueOf(actualValue));
27: }
28:
29: public StepFailedException(final String message,
30: final String expectedValue, final String actualValue) {
31: this (message, expectedValue, actualValue, null);
32: }
33:
34: public StepFailedException(final String message,
35: final Step failedStep) {
36: super (message, failedStep);
37: }
38:
39: public StepFailedException(final String message,
40: final Exception cause) {
41: super (message, cause);
42: }
43:
44: /**
45: * Indicates if the provided exception is caused by a {@link StepFailedException}.
46: * Even if {@link StepFailedException} extends {@link BuildException} in some cases
47: * (for instance failed macro) the original {@link StepFailedException} is wrapped
48: * within a {@link BuildException}.
49: * @param e the exception to analyze
50: * @return <code>true</code> if the cause is a {@link StepFailedException}
51: */
52: public static boolean isCausedByStepFailedException(
53: final Throwable e) {
54: Throwable cause = e;
55: while (cause != null) {
56: if (cause instanceof StepFailedException)
57: return true;
58: cause = cause.getCause();
59: }
60:
61: return false;
62: }
63: }
|