now allowing components and interfaces to be added after construction.
[utils] / support / general / src / test / java / org / wamblee / test / AssertionUtils.java
index 8d179db7ad1d488a9d53361c414b3adea6d1e5f8..767f679c9be45026010a959110afdf7328aaac54 100644 (file)
@@ -16,6 +16,7 @@
 package org.wamblee.test;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -35,6 +36,25 @@ public final class AssertionUtils {
     private AssertionUtils() {
         // Empty
     }
+    
+    /**
+     * Asserts that two collections are equal including equality of the elements. 
+     * @param aExpected
+     * @param aActual
+     */
+    public static void assertEquals(List aExpected, List aActual) { 
+       assertEquals(aExpected.toArray(), aActual.toArray());
+    }
+    
+    /**
+     * Asserts that two collections are equal including equality of the elements. 
+     * @param aMsg
+     * @param aExpected
+     * @param aActual
+     */
+    public static void assertEquals(String aMsg, List aExpected, List aActual) { 
+       assertEquals(aMsg, aExpected.toArray(), aActual.toArray());
+    }
 
     /**
      * Asserts that two object arrays are equal.
@@ -117,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);
+               }
+       }
+    }
 }