[jboss-cvs] JBossAS SVN: r62653 - projects/test/trunk/src/main/java/org/jboss/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 30 14:18:13 EDT 2007
Author: adrian at jboss.org
Date: 2007-04-30 14:18:12 -0400 (Mon, 30 Apr 2007)
New Revision: 62653
Modified:
projects/test/trunk/src/main/java/org/jboss/test/AbstractTestCase.java
Log:
Add extra Throwable checks for deep throwable checking
and rethrowing the exception if it does not match rather than throwing AssertionFailedError.
Modified: projects/test/trunk/src/main/java/org/jboss/test/AbstractTestCase.java
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/AbstractTestCase.java 2007-04-30 17:56:13 UTC (rev 62652)
+++ projects/test/trunk/src/main/java/org/jboss/test/AbstractTestCase.java 2007-04-30 18:18:12 UTC (rev 62653)
@@ -36,6 +36,7 @@
import junit.framework.TestCase;
import org.jboss.logging.Logger;
+import org.jboss.util.UnexpectedThrowable;
/**
* An abstract Test Case.
@@ -234,8 +235,94 @@
staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")");
}
}
+
+ /**
+ * Check a throwable and rethrow if it doesn't match
+ *
+ * @param expected the expected throwable
+ * @param throwable the throwable
+ * @throws Exception the thrown exception
+ */
+ public static void checkThrowableRethrow(Class<? extends Throwable> expected, Throwable throwable) throws Exception
+ {
+ assertNotNull(expected);
+ assertNotNull(throwable);
+
+ if (expected.equals(throwable.getClass()) == false)
+ {
+ if (throwable instanceof Exception)
+ throw (Exception) throwable;
+ else if (throwable instanceof Error)
+ throw (Error) throwable;
+ else
+ throw new UnexpectedThrowable("UnexpectedThrowable", throwable);
+ }
+ else
+ {
+ staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")");
+ }
+ }
/**
+ * Check we have the expected deep exception
+ *
+ * @param expected the excepted class of the exception
+ * @param throwable the real exception
+ */
+ public static void checkDeepThrowable(Class<? extends Throwable> expected, Throwable throwable)
+ {
+ assertNotNull(expected);
+ assertNotNull(throwable);
+
+ while (throwable.getCause() != null)
+ throwable = throwable.getCause();
+
+ if (throwable instanceof AssertionFailedError || throwable instanceof AssertionError)
+ throw (Error) throwable;
+ if (expected.equals(throwable.getClass()) == false)
+ {
+ staticLog.error("Unexpected throwable", throwable);
+ fail("Unexpected throwable: " + throwable);
+ }
+ else
+ {
+ staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")");
+ }
+ }
+
+ /**
+ * Check a deep throwable and rethrow if it doesn't match
+ *
+ * @param expected the expected throwable
+ * @param throwable the throwable
+ * @throws Exception the thrown exception
+ */
+ public static void checkDeepThrowableRethrow(Class<? extends Throwable> expected, Throwable throwable) throws Exception
+ {
+ assertNotNull(expected);
+ assertNotNull(throwable);
+
+ Throwable original = throwable;
+
+ while (throwable.getCause() != null)
+ throwable = throwable.getCause();
+
+ if (expected.equals(throwable.getClass()) == false)
+ {
+ if (original instanceof Exception)
+ throw (Exception) original;
+ else if (original instanceof Error)
+ throw (Error) original;
+ else
+ throw new UnexpectedThrowable("UnexpectedThrowable", original);
+ }
+ else
+ {
+ staticLog.debug("Got expected " + expected.getName() + "(" + throwable + ")");
+ }
+ }
+
+ /**
* Serialize an object
*
* @param object the object
More information about the jboss-cvs-commits
mailing list