[jboss-cvs] JBossAS SVN: r59931 - projects/test/trunk/test/src/main/org/jboss/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 23 07:34:16 EST 2007
Author: alesj
Date: 2007-01-23 07:34:16 -0500 (Tue, 23 Jan 2007)
New Revision: 59931
Modified:
projects/test/trunk/test/src/main/org/jboss/test/AbstractTestCase.java
Log:
Added assertInstanceOf.
Modified: projects/test/trunk/test/src/main/org/jboss/test/AbstractTestCase.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/AbstractTestCase.java 2007-01-22 23:40:41 UTC (rev 59930)
+++ projects/test/trunk/test/src/main/org/jboss/test/AbstractTestCase.java 2007-01-23 12:34:16 UTC (rev 59931)
@@ -236,6 +236,48 @@
}
/**
+ * Check we have the expected type
+ *
+ * @param <T> the expected type
+ * @param o the object
+ * @param expectedType the excepted class of the exception
+ * @return the expected type
+ */
+ protected <T> T assertInstanceOf(Object o, Class<T> expectedType)
+ {
+ return assertInstanceOf(o, expectedType, true);
+ }
+
+ /**
+ * Check we have the expected type
+ *
+ * @param <T> the expected type
+ * @param o the object
+ * @param expectedType the excepted class of the exception
+ * @param allowNull whether the object can be null
+ * @return the expected type
+ */
+ protected <T> T assertInstanceOf(Object o, Class<T> expectedType, boolean allowNull)
+ {
+ if (expectedType == null)
+ fail("Null expectedType");
+
+ if (o == null && allowNull)
+ return null;
+
+ try
+ {
+ return expectedType.cast(o);
+ }
+ catch (ClassCastException e)
+ {
+ fail("Object " + o + " of class " + o.getClass().getName() + " is not an instanceof " + expectedType.getName());
+ // should not reach this
+ return null;
+ }
+ }
+
+ /**
* Log an event with the given context
*
* @param context the context
More information about the jboss-cvs-commits
mailing list