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 assertMessageCauseConstructorBehavesAsExpected(exceptionClass); } - public static void assertBehavesLikeDebuggableException(Class exceptionClass) + public static void assertBehavesLikeDebuggableException(Class exceptionClass) throws Exception { assertBehavesLikeStandardException(exceptionClass); @@ -126,22 +126,24 @@ private static void assertMessageCauseConstructorBehavesAsExpected(Class exceptionClass) throws Exception { - DebuggableException exceptionInstance = exceptionClass.getConstructor(DebugInformation.class).newInstance( + Class 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 void assertDebugInformationCauseConstructorBehavesAsExpected( + private static void assertDebugInformationCauseConstructorBehavesAsExpected( Class exceptionClass) throws Exception { T exceptionInstance = exceptionClass.getConstructor(DebugInformation.class, Throwable.class).newInstance( DEBUG_INFORMATION_REFERENCE, CAUSE_EXCEPTION); @@ -152,10 +154,10 @@ private static void assertDebugInformationCauseC T deserializedInstance = exceptionClass.cast( TestSerializationHelper.serializeAndDeserialize(exceptionInstance)); assertExceptionEqualTo("serialization", exceptionInstance, deserializedInstance); - assertHaveEqualDebugInformation(exceptionInstance, deserializedInstance); + assertHaveEqualDebugInformation((DebuggableObject) exceptionInstance, (DebuggableObject) deserializedInstance); } - private static void assertMessageDebugInformationConstructorBehavesAsExpected( + private static void assertMessageDebugInformationConstructorBehavesAsExpected( Class exceptionClass) throws Exception { T exceptionInstance = exceptionClass.getConstructor(String.class, DebugInformation.class).newInstance( MESSAGE_REFERENCE, DEBUG_INFORMATION_REFERENCE); @@ -166,10 +168,10 @@ private static void assertMessageDebugInformatio T deserializedInstance = exceptionClass.cast( TestSerializationHelper.serializeAndDeserialize(exceptionInstance)); assertExceptionEqualTo("serialization", exceptionInstance, deserializedInstance); - assertHaveEqualDebugInformation(exceptionInstance, deserializedInstance); + assertHaveEqualDebugInformation((DebuggableObject) exceptionInstance, (DebuggableObject) deserializedInstance); } - private static void assertMessageDebugInformationCauseConstructorBehavesAsExpected( + private static void assertMessageDebugInformationCauseConstructorBehavesAsExpected( Class exceptionClass) throws Exception { T exceptionInstance = exceptionClass.getConstructor(String.class, DebugInformation.class, Throwable.class).newInstance(MESSAGE_REFERENCE, DEBUG_INFORMATION_REFERENCE, CAUSE_EXCEPTION); @@ -181,7 +183,7 @@ private static void assertMessageDebugInformatio T deserializedInstance = exceptionClass.cast( TestSerializationHelper.serializeAndDeserialize(exceptionInstance)); assertExceptionEqualTo("serialization", exceptionInstance, deserializedInstance); - assertHaveEqualDebugInformation(exceptionInstance, deserializedInstance); + assertHaveEqualDebugInformation((DebuggableObject) exceptionInstance, (DebuggableObject) deserializedInstance); } //