+
+ public static interface ErroneousCode {
+ void run() throws Exception;
+ }
+
+ /**
+ * Asserts that an exception occurs.
+ * @param aRunnable Test cases should create a subclass of this which contains the
+ * code that should throw an exception.
+ * @param aType Type of exception that is expected.
+ */
+ public static void assertException(ErroneousCode aObject, Class aType) {
+ try {
+ aObject.run();
+ throw new RuntimeException("No exception occurred");
+ } catch (Throwable t) {
+ if ( aType.isInstance(t)) {
+ return; // ok
+ }
+ else {
+ throw new RuntimeException(t);
+ }
+ }
+ }