now allowing components and interfaces to be added after construction.
[utils] / support / general / src / test / java / org / wamblee / test / AssertionUtils.java
index fc4040721d9aabeffac4017ad0b5f4907caa0529..767f679c9be45026010a959110afdf7328aaac54 100644 (file)
@@ -137,4 +137,27 @@ public final class AssertionUtils {
                     aExpectedMap.get(key), aActual.get(key));
         }
     }
+   
+    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();
+       } catch (Throwable t) { 
+               if ( aType.isInstance(t)) { 
+                       return; // ok 
+               }
+               else { 
+                       throw new RuntimeException(t);
+               }
+       }
+    }
 }