diff --git a/src/main/java/org/opentest4j/AssertionFailedException.java b/src/main/java/org/opentest4j/AssertionFailedException.java index 59836af..58f4c1f 100644 --- a/src/main/java/org/opentest4j/AssertionFailedException.java +++ b/src/main/java/org/opentest4j/AssertionFailedException.java @@ -17,6 +17,7 @@ package org.opentest4j; import org.opentest4j.debug.DebugInformation; +import org.opentest4j.debug.DebuggableObject; /** *
@@ -35,39 +36,54 @@
* @author Mark Michaelis
* @since 1.0
*/
-public class AssertionFailedException extends DebuggableException {
+public class AssertionFailedException extends AssertionError implements DebuggableObject {
private static final long serialVersionUID = 1L;
+ private final DebugInformation debugInformation;
public AssertionFailedException() {
+ this((DebugInformation) null);
}
public AssertionFailedException(String message) {
- super(message);
+ this(message, (DebugInformation) null);
}
public AssertionFailedException(String message, Throwable cause) {
- super(message, cause);
+ this(message, null, cause);
}
public AssertionFailedException(Throwable cause) {
- super(cause);
+ this((DebugInformation) null, cause);
}
public AssertionFailedException(DebugInformation debugInformation) {
- super(debugInformation);
+ this.debugInformation = debugInformation;
}
public AssertionFailedException(String message, DebugInformation debugInformation) {
- super(message, debugInformation);
+ super(message);
+ this.debugInformation = debugInformation;
}
public AssertionFailedException(String message, DebugInformation debugInformation, Throwable cause) {
- super(message, debugInformation, cause);
+ super(message);
+ this.initCause(cause);
+ this.debugInformation = debugInformation;
}
public AssertionFailedException(DebugInformation debugInformation, Throwable cause) {
- super(debugInformation, cause);
+ super(cause);
+ this.debugInformation = debugInformation;
+ }
+
+ @Override
+ public DebugInformation getDebugInformation() {
+ return this.debugInformation;
}
+ @Override
+ public boolean hasDebugInformation() {
+ return this.debugInformation != null;
+ }
}
diff --git a/src/test/java/org/opentest4j/ExceptionTestHelper.java b/src/test/java/org/opentest4j/ExceptionTestHelper.java
index 5483895..dc97fea 100644
--- a/src/test/java/org/opentest4j/ExceptionTestHelper.java
+++ b/src/test/java/org/opentest4j/ExceptionTestHelper.java
@@ -52,7 +52,7 @@ public static void assertBehavesLikeStandardException(Class extends Throwable>
assertMessageCauseConstructorBehavesAsExpected(exceptionClass);
}
- public static void assertBehavesLikeDebuggableException(Class extends DebuggableException> exceptionClass)
+ public static void assertBehavesLikeDebuggableException(Class extends Throwable> exceptionClass)
throws Exception {
assertBehavesLikeStandardException(exceptionClass);
@@ -126,22 +126,24 @@ private static void assertMessageCauseConstructorBehavesAsExpected(Class exten
//------------------------------------------------------------------------------------------------------------------
private static void assertOnlyDebugInformationConstructorBehavesAsExpected(
- Class extends DebuggableException> exceptionClass) throws Exception {
- DebuggableException exceptionInstance = exceptionClass.getConstructor(DebugInformation.class).newInstance(
+ Class extends Throwable> exceptionClass) throws Exception {
+ Throwable exceptionInstance = exceptionClass.getConstructor(DebugInformation.class).newInstance(
DEBUG_INFORMATION_REFERENCE);
assertExceptionSimilarTo("only debuginformation", EXCEPTION_REFERENCE_NO_ARG, exceptionInstance);
assertCanInitCause(exceptionInstance);
- assertTrue("hasDebugInformation", exceptionInstance.hasDebugInformation());
- assertSame("debugInformation", DEBUG_INFORMATION_REFERENCE, exceptionInstance.getDebugInformation());
+ assertTrue("instance of DebuggableObject", exceptionInstance instanceof DebuggableObject);
+ DebuggableObject debuggableObject = (DebuggableObject) exceptionInstance;
+ assertTrue("hasDebugInformation", debuggableObject.hasDebugInformation());
+ assertSame("debugInformation", DEBUG_INFORMATION_REFERENCE, debuggableObject.getDebugInformation());
- DebuggableException deserializedInstance = exceptionClass.cast(
+ Throwable deserializedInstance = exceptionClass.cast(
TestSerializationHelper.serializeAndDeserialize(exceptionInstance));
assertExceptionEqualTo("serialization", exceptionInstance, deserializedInstance);
- assertHaveEqualDebugInformation(exceptionInstance, deserializedInstance);
+ assertHaveEqualDebugInformation((DebuggableObject) exceptionInstance, (DebuggableObject) deserializedInstance);
}
- private static